├── banner.jpg ├── banner2.jpg ├── README.md ├── LICENSE └── BakeLab_1_2.py /banner.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/specoolar/Bakelab-Blender-addon/HEAD/banner.jpg -------------------------------------------------------------------------------- /banner2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/specoolar/Bakelab-Blender-addon/HEAD/banner2.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Bakelab-Blender-addon 2 | 3 | ![image1](https://github.com/Shahzod114/Bakelab-Blender-addon/blob/master/banner.jpg) 4 | BakeLab - A blender addon for baking images.
5 | Compatible with Blender 2.79
6 | For blender version 2.81+ go to [BakeLab 2](https://github.com/Shahzod114/Blender-BakeLab2) 7 | 8 | Main Features: 9 | * Automatically unwrap objects, create images, bake objects, save/pack images, generate materials in one click; 10 | * Support for both Cycles and BI render engines; 11 | * Anti-Aliased baking; 12 | * Custom passes(for Cycles). bake any attributes from your material(Roughness, Metallic, Specular and etc); 13 | * Advanced Normal Baking For Cycles. Now in Cycles you can bake normals/bumps plugged into BSDFs; 14 | * Unwrap and Bake Multiple Objects into one map; 15 | * Automatically Generating Materials for both Cycles and BI; 16 | 17 | ![image2](https://github.com/Shahzod114/Bakelab-Blender-addon/blob/master/banner2.jpg) 18 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /BakeLab_1_2.py: -------------------------------------------------------------------------------- 1 | bl_info = { 2 | "name": "BakeLab", 3 | "description": "Bake Multiple Different Types Of Maps in One Click", 4 | "author": "Shahzod Boyxonov", 5 | "version": (1, 2, 0), 6 | "blender": (2, 79, 0), 7 | "location": "View3D > Tools Panel > BakeLab", 8 | "category": "Render" 9 | } 10 | 11 | import bpy 12 | import bgl 13 | import blf 14 | 15 | def BakeLab_DrawProgressBar(y_shift,progress,text): 16 | bgl.glColor4f(0,0,0,1.0) 17 | bgl.glBegin(bgl.GL_QUADS) 18 | bgl.glVertex2i(19, y_shift-1) 19 | bgl.glVertex2i(161, y_shift-1) 20 | bgl.glVertex2i(161, y_shift+31) 21 | bgl.glVertex2i(19, y_shift+31) 22 | bgl.glEnd() 23 | bgl.glColor4f(0.7,0.5,0.3, 1.0) 24 | bgl.glBegin(bgl.GL_QUADS) 25 | bgl.glVertex2i(20, y_shift) 26 | bgl.glVertex2i(160, y_shift) 27 | bgl.glVertex2i(160, y_shift+30) 28 | bgl.glVertex2i(20, y_shift+30) 29 | bgl.glEnd() 30 | bgl.glColor4f(0.05,0.1,0.15, 1.0) 31 | bgl.glBegin(bgl.GL_QUADS) 32 | bgl.glVertex2i(21, y_shift+1) 33 | bgl.glVertex2i(159, y_shift+1) 34 | bgl.glVertex2i(159, y_shift+29) 35 | bgl.glVertex2i(21, y_shift+29) 36 | bgl.glEnd() 37 | bgl.glColor4f(0.7,0.5,0.3, 1.0) 38 | bgl.glBegin(bgl.GL_QUADS) 39 | x_loc = (157-23)*progress+23 40 | bgl.glVertex2i(23, y_shift+3) 41 | bgl.glVertex2i(int(x_loc), y_shift+3) 42 | bgl.glVertex2i(int(x_loc), y_shift+27) 43 | bgl.glVertex2i(23, y_shift+27) 44 | bgl.glEnd() 45 | blf.position(0, 170, y_shift+10, 0) 46 | blf.draw(0, text) 47 | 48 | def BakeLab_DrawCallback(self, context): 49 | props = context.scene.BakeLabProps 50 | ww = context.area.width 51 | wh = context.area.height 52 | 53 | bgl.glEnable(bgl.GL_BLEND) 54 | blf.enable(0,blf.SHADOW) 55 | blf.shadow(0,5,0,0.0,0.0,1) 56 | 57 | ######### Title { 58 | bgl.glBegin(bgl.GL_QUADS) 59 | bgl.glColor4f(0.88, 0.87, 0.85, 0.1) 60 | for i in range(0,20): 61 | bgl.glVertex2i(0, wh) 62 | bgl.glVertex2i(120+i*3, wh) 63 | bgl.glVertex2i(120+i*3, wh-70) 64 | bgl.glVertex2i(0, wh-70) 65 | 66 | bgl.glColor4f(0.7,0.1,0.3, 0.1) 67 | for i in range(0,20): 68 | bgl.glVertex2i(0, wh-70) 69 | bgl.glVertex2i(140+i*3, wh-70) 70 | bgl.glVertex2i(140+i*3, wh-75) 71 | bgl.glVertex2i(0, wh-75) 72 | bgl.glEnd() 73 | 74 | blf.size(0, 30, 72) 75 | bgl.glColor4f(0.7,0.1,0.3, 1.0) 76 | blf.position(0, 15, context.area.height-58, 0) 77 | blf.draw(0, 'BakeLab') 78 | ######### } 79 | 80 | ######### Progress { 81 | blf.size(0, 15, 72) 82 | y_shift = 15 83 | ####################################################################### 84 | cur = self.bake_item_id 85 | max = len(context.scene.BakeLabMapColl) 86 | BakeLab_DrawProgressBar(y_shift,cur/max,'Map: '+ str(cur)+' of '+str(max)) 87 | y_shift += 30 88 | ####################################################################### 89 | if not props.s_to_a and not props.all_in_one: 90 | cur = self.bake_obj_id 91 | max = len(self.bake_objs) 92 | BakeLab_DrawProgressBar(y_shift,cur/max,'Object: '+ str(cur)+' of '+str(max)) 93 | y_shift += 30 94 | ####################################################################### 95 | if props.use_list: 96 | cur = self.ObjListIndex 97 | max = len(context.scene.BakeLabObjColl) 98 | BakeLab_DrawProgressBar(y_shift,cur/max,'List: '+ str(cur)+' of '+str(max)) 99 | y_shift += 30 100 | ####################################################################### 101 | ######### } 102 | 103 | 104 | blf.disable(0,blf.SHADOW) 105 | bgl.glDisable(bgl.GL_BLEND) 106 | bgl.glColor4f(0.0, 0.0, 0.0, 1.0) 107 | 108 | class baker: 109 | def __init__(self, type, image, item, 110 | engine = 'CYCLES', samples = 16): 111 | self.type = type 112 | self.image = image 113 | self.item = item 114 | self.engine = engine 115 | self.samples = samples 116 | 117 | def bake(self): 118 | if self.engine == 'CYCLES': 119 | ############################ CYCLES ############################### 120 | bpy.context.scene.cycles.samples = self.samples 121 | 122 | if bpy.ops.object.bake('INVOKE_DEFAULT',type = self.type)=={'CANCELLED'}: 123 | return False 124 | else: 125 | ############################ BI ############################### 126 | if bpy.context.scene.world: 127 | bpy.context.scene.world.light_settings.samples = self.samples 128 | 129 | bpy.context.scene.render.bake_type = self.type 130 | if bpy.ops.object.bake_image('INVOKE_DEFAULT')=={'CANCELLED'}: 131 | return False 132 | 133 | return True 134 | 135 | ############################################################################################ 136 | ############################################################################################ 137 | ############################################################################################ 138 | ############################################################################################ 139 | ############################################################################################ 140 | 141 | class BakeLab(bpy.types.Operator): 142 | bl_idname = 'bakelab.bake' 143 | bl_label = 'BakeLab' 144 | bl_options = {'REGISTER','UNDO'} 145 | TMP_IMG_NODE_NAME = 'BAKELAB_IMAGE_NODE_TMP' 146 | TMP_COPY_MAT_NAME = 'BAKELAB_TMP_COPY_MAT_' 147 | 148 | def save_defaults(self,context): 149 | self.cur_engine = bpy.context.scene.render.engine 150 | self.cycles_device = bpy.context.scene.cycles.device 151 | self.s2a = context.scene.render.use_bake_selected_to_active 152 | self.c_s2a = context.scene.render.bake.use_selected_to_active 153 | self.b_bake_margin = context.scene.render.bake_margin 154 | self.c_bake_margin = context.scene.render.bake.margin 155 | self.bake_type = context.scene.render.bake_type 156 | self.active_object = context.scene.objects.active 157 | self.selected_objects = [i for i in context.selected_objects] 158 | self.normalize = context.scene.render.use_bake_normalize 159 | self.normal_space = context.scene.render.bake_normal_space 160 | self.c_normal_space = context.scene.render.bake.normal_space 161 | 162 | self.use_pass_direct = context.scene.render.bake.use_pass_direct 163 | self.use_pass_indirect = context.scene.render.bake.use_pass_indirect 164 | self.use_pass_color = context.scene.render.bake.use_pass_color 165 | 166 | self.use_pass_diffuse = context.scene.render.bake.use_pass_diffuse 167 | self.use_pass_glossy = context.scene.render.bake.use_pass_glossy 168 | self.use_pass_trans = context.scene.render.bake.use_pass_transmission 169 | self.use_pass_sss = context.scene.render.bake.use_pass_subsurface 170 | self.use_pass_ao = context.scene.render.bake.use_pass_ambient_occlusion 171 | self.use_pass_emit = context.scene.render.bake.use_pass_emit 172 | 173 | self.bake_distance = context.scene.render.bake_distance 174 | self.use_cage = context.scene.render.bake.use_cage 175 | self.cage_extrusion = context.scene.render.bake.cage_extrusion 176 | self.cage_object = context.scene.render.bake.cage_object 177 | 178 | if bpy.context.scene.world: 179 | self.bi_samples = bpy.context.scene.world.light_settings.samples 180 | self.cy_samples = bpy.context.scene.cycles.samples 181 | 182 | def restore_defaults(self,context): 183 | bpy.context.scene.render.engine = self.cur_engine 184 | bpy.context.scene.cycles.device = self.cycles_device 185 | context.scene.render.use_bake_selected_to_active = self.s2a 186 | context.scene.render.bake.use_selected_to_active = self.c_s2a 187 | context.scene.render.bake_margin = self.b_bake_margin 188 | context.scene.render.bake.margin = self.c_bake_margin 189 | context.scene.render.bake_type = self.bake_type 190 | context.scene.objects.active = self.active_object 191 | bpy.ops.object.select_all(action = 'DESELECT') 192 | for obj in self.selected_objects: 193 | obj.select = True 194 | context.scene.render.use_bake_normalize = self.normalize 195 | context.scene.render.bake_normal_space = self.normal_space 196 | context.scene.render.bake.normal_space = self.c_normal_space 197 | 198 | context.scene.render.bake.use_pass_direct = self.use_pass_direct 199 | context.scene.render.bake.use_pass_indirect = self.use_pass_indirect 200 | context.scene.render.bake.use_pass_color = self.use_pass_color 201 | 202 | context.scene.render.bake.use_pass_diffuse = self.use_pass_diffuse 203 | context.scene.render.bake.use_pass_glossy = self.use_pass_glossy 204 | context.scene.render.bake.use_pass_transmission = self.use_pass_trans 205 | context.scene.render.bake.use_pass_subsurface = self.use_pass_sss 206 | context.scene.render.bake.use_pass_ambient_occlusion = self.use_pass_ao 207 | context.scene.render.bake.use_pass_emit = self.use_pass_emit 208 | 209 | context.scene.render.bake_distance = self.bake_distance 210 | context.scene.render.bake.use_cage = self.use_cage 211 | context.scene.render.bake.cage_extrusion = self.cage_extrusion 212 | context.scene.render.bake.cage_object = self.cage_object 213 | 214 | if bpy.context.scene.world: 215 | bpy.context.scene.world.light_settings.samples = self.bi_samples 216 | bpy.context.scene.cycles.samples = self.cy_samples 217 | 218 | def unwrap(self,props,obj): 219 | if props.newuv: 220 | obj.data.uv_textures.active = obj.data.uv_textures.new(name = 'UVMap_BAKELAB') 221 | elif obj.data.uv_textures.active: 222 | return 223 | bpy.ops.object.mode_set(mode='EDIT') 224 | bpy.ops.mesh.select_all(action = 'SELECT') 225 | if props.unwrap_mode == 'smart_uv': 226 | bpy.ops.uv.smart_project(angle_limit = props.smart_uv_angle, 227 | island_margin = props.smart_uv_margin) 228 | elif props.unwrap_mode == 'lightmap': 229 | bpy.ops.uv.lightmap_pack(PREF_BOX_DIV = props.lightmap_quality, 230 | PREF_MARGIN_DIV = props.lightmap_margin) 231 | bpy.ops.object.mode_set(mode='OBJECT') 232 | 233 | 234 | def createTmpImageNodes(self,obj,image): 235 | for slot in obj.material_slots: 236 | mat = slot.material 237 | mat.use_nodes = True 238 | nodes = mat.node_tree.nodes 239 | for node in nodes: 240 | node.select = False 241 | if self.TMP_IMG_NODE_NAME in nodes: 242 | imgNode = nodes[self.TMP_IMG_NODE_NAME] 243 | else: 244 | imgNode = nodes.new(type = 'ShaderNodeTexImage') 245 | imgNode.name = self.TMP_IMG_NODE_NAME 246 | imgNode.select = True 247 | nodes.active = imgNode 248 | imgNode.image = image 249 | 250 | def removeTmpImageNodes(self,obj_list): 251 | for obj in obj_list: 252 | for slot in obj.material_slots: 253 | mat = slot.material 254 | if not mat: continue 255 | if not mat.node_tree: continue 256 | nodes = mat.node_tree.nodes 257 | if self.TMP_IMG_NODE_NAME in nodes: 258 | nodes.remove(nodes[self.TMP_IMG_NODE_NAME]) 259 | 260 | def add_empty_mat(self,obj): 261 | if len(obj.material_slots)==0: 262 | bpy.ops.object.material_slot_add() 263 | 264 | if not self.empty_mat: 265 | self.empty_mat = bpy.data.materials.new('BAKELAB_EMPTY_MAT') 266 | self.trash_mats.append(self.empty_mat) 267 | for slot in obj.material_slots: 268 | if slot.material is None: 269 | slot.material = self.empty_mat 270 | 271 | def passes_to_rgb(self,node,src_socket,nodes,links,passes,multiplier,addend): 272 | has_bsdf = False 273 | for input in node.inputs: 274 | if input.type == 'SHADER': 275 | has_bsdf = True 276 | if len(input.links): 277 | self.passes_to_rgb(input.links[0].from_node,input, 278 | nodes,links,passes,multiplier,addend) 279 | 280 | if not has_bsdf: 281 | emit = nodes.new(type = 'ShaderNodeEmission') 282 | final_value = 0.0 * multiplier + addend 283 | emit.inputs[0].default_value = final_value,final_value,final_value,final_value 284 | links.new(emit.outputs[0],src_socket) 285 | ####### Find Pass Input Socket{ 286 | pass_input = None 287 | for Pass in passes: 288 | pass_input = node.inputs.get(Pass) 289 | if pass_input: break 290 | ####### } 291 | if pass_input: 292 | if len(pass_input.links): 293 | out_socket = pass_input.links[0].from_socket 294 | mul = nodes.new(type = 'ShaderNodeMixRGB') 295 | add = nodes.new(type = 'ShaderNodeMixRGB') 296 | mul.inputs[0].default_value = 1 297 | add.inputs[0].default_value = 1 298 | mul.blend_type = 'MULTIPLY' 299 | mul.inputs[2].default_value = multiplier,multiplier,multiplier,multiplier 300 | if addend >= 0: 301 | add.blend_type = 'ADD' 302 | add.inputs[2].default_value = addend,addend,addend,addend 303 | else: 304 | add.blend_type = 'SUBTRACT' 305 | add.inputs[2].default_value = -addend,-addend,-addend,-addend 306 | 307 | links.new(out_socket, mul.inputs[1]) 308 | links.new(mul.outputs[0], add.inputs[1]) 309 | links.new(add.outputs[0], emit.inputs[0]) 310 | else: 311 | if pass_input.type == 'RGBA': 312 | emit.inputs[0].default_value[0] = pass_input.default_value[0] * multiplier + addend 313 | emit.inputs[0].default_value[1] = pass_input.default_value[1] * multiplier + addend 314 | emit.inputs[0].default_value[2] = pass_input.default_value[2] * multiplier + addend 315 | emit.inputs[0].default_value[3] = pass_input.default_value[3] * multiplier + addend 316 | elif pass_input.type == 'VECTOR': 317 | emit.inputs[0].default_value[0] = pass_input.default_value[0] * multiplier + addend 318 | emit.inputs[0].default_value[1] = pass_input.default_value[1] * multiplier + addend 319 | emit.inputs[0].default_value[2] = pass_input.default_value[2] * multiplier + addend 320 | emit.inputs[0].default_value[3] = 1 321 | elif pass_input.type == 'VALUE': 322 | emit.inputs[0].default_value[0] = pass_input.default_value * multiplier + addend 323 | emit.inputs[0].default_value[1] = pass_input.default_value * multiplier + addend 324 | emit.inputs[0].default_value[2] = pass_input.default_value * multiplier + addend 325 | emit.inputs[0].default_value[3] = 1 326 | 327 | def passes_to_emit_node(self,obj,passes,multiplier,addend): 328 | for slot in obj.material_slots: 329 | nodes = slot.material.node_tree.nodes 330 | links = slot.material.node_tree.links 331 | 332 | ##### Find Output Node 333 | out = None 334 | for node in nodes: 335 | if node.type == 'OUTPUT_MATERIAL': 336 | out = node 337 | break 338 | 339 | if out: 340 | #### Modify Nodes 341 | self.passes_to_rgb(out,None,nodes,links,passes,multiplier,addend) 342 | else: 343 | #### Create Default Texture Nodes 344 | out = nodes.new(type = 'ShaderNodeOutputMaterial') 345 | emit = nodes.new(type = 'ShaderNodeEmission') 346 | final_value = 0.0 * multiplier + addend 347 | emit.inputs[0].default_value = final_value,final_value,final_value,final_value 348 | links.new(emit.outputs[0],out.inputs[0]) 349 | 350 | def normal_to_rgb(self,node,src_socket,nodes,links,normal_socket): 351 | has_bsdf = False 352 | for input in node.inputs: 353 | if input.type == 'SHADER': 354 | has_bsdf = True 355 | if len(input.links): 356 | self.normal_to_rgb(input.links[0].from_node,input, 357 | nodes,links,normal_socket) 358 | else: 359 | emit = nodes.new(type = 'ShaderNodeEmission') 360 | links.new(normal_socket,emit.inputs[0]) 361 | links.new(emit.outputs[0],input) 362 | 363 | if not has_bsdf: 364 | emit = nodes.new(type = 'ShaderNodeEmission') 365 | links.new(emit.outputs[0],src_socket) 366 | normal_input = node.inputs.get('Normal') 367 | if normal_input: 368 | if len(normal_input.links): 369 | out_socket = normal_input.links[0].from_socket 370 | add = nodes.new(type = 'ShaderNodeMixRGB') 371 | div = nodes.new(type = 'ShaderNodeMixRGB') 372 | add.blend_type = 'ADD' 373 | div.blend_type = 'DIVIDE' 374 | add.inputs[0].default_value = 1 375 | div.inputs[0].default_value = 1 376 | add.inputs[2].default_value = 1,1,1,1 377 | div.inputs[2].default_value = 2,2,2,1 378 | links.new(out_socket ,add.inputs[1]) 379 | links.new(add.outputs[0],div.inputs[1]) 380 | links.new(div.outputs[0],emit.inputs[0]) 381 | else: 382 | links.new(normal_socket,emit.inputs[0]) 383 | else: 384 | links.new(normal_socket,emit.inputs[0]) 385 | 386 | def normals_to_emit_node(self,obj): 387 | for slot in obj.material_slots: 388 | nodes = slot.material.node_tree.nodes 389 | links = slot.material.node_tree.links 390 | 391 | ###### Create Default Normal Socket 392 | geo = nodes.new(type = 'ShaderNodeNewGeometry') 393 | add = nodes.new(type = 'ShaderNodeMixRGB') 394 | div = nodes.new(type = 'ShaderNodeMixRGB') 395 | add.blend_type = 'ADD' 396 | div.blend_type = 'DIVIDE' 397 | add.inputs[0].default_value = 1 398 | div.inputs[0].default_value = 1 399 | add.inputs[2].default_value = 1,1,1,1 400 | div.inputs[2].default_value = 2,2,2,1 401 | links.new(geo.outputs[1],add.inputs[1]) 402 | links.new(add.outputs[0],div.inputs[1]) 403 | normal_socket = div.outputs[0] 404 | 405 | ##### Find Output Node 406 | out = None 407 | for node in nodes: 408 | if node.type == 'OUTPUT_MATERIAL': 409 | out = node 410 | break 411 | 412 | if out: 413 | #### Modify Nodes 414 | self.normal_to_rgb(out,None,nodes,links,normal_socket) 415 | else: 416 | #### Create Default Normal Nodes 417 | out = nodes.new(type = 'ShaderNodeOutputMaterial') 418 | emit = nodes.new(type = 'ShaderNodeEmission') 419 | links.new(normal_socket,emit.inputs[0]) 420 | links.new(emit.outputs[0],out.inputs[0]) 421 | 422 | 423 | def create_normal_transfer_material(self,src_image,dst_image,normal_space): 424 | mat = bpy.data.materials.new('BAKELAB_NORMAL_TRANSFER_MAT') 425 | mat.use_nodes = True 426 | nodes = mat.node_tree.nodes 427 | links = mat.node_tree.links 428 | nodes.clear() 429 | 430 | src = nodes.new(type = 'ShaderNodeTexImage') # Source Image 431 | src.image = src_image 432 | mul = nodes.new(type = 'ShaderNodeMixRGB') 433 | sub = nodes.new(type = 'ShaderNodeMixRGB') 434 | mul.blend_type = 'MULTIPLY' 435 | sub.blend_type = 'SUBTRACT' 436 | mul.inputs[0].default_value = 1 437 | sub.inputs[0].default_value = 1 438 | mul.inputs[2].default_value = 2,2,2,1 439 | sub.inputs[2].default_value = 1,1,1,1 440 | links.new(src.outputs[0],mul.inputs[1]) 441 | links.new(mul.outputs[0],sub.inputs[1]) 442 | bump_normal = sub.outputs[0] 443 | 444 | if normal_space == 'TANGENT': 445 | geo = nodes.new(type = 'ShaderNodeNewGeometry') 446 | tan = nodes.new(type = 'ShaderNodeTangent') 447 | c_b = nodes.new(type = 'ShaderNodeVectorMath') 448 | tan.direction_type = 'UV_MAP' 449 | c_b.operation = 'CROSS_PRODUCT' 450 | normal = geo.outputs[1] # Normal 451 | tangent = tan.outputs[0] # Tangent 452 | binormal = c_b.outputs[0] # Binormal 453 | links.new(normal,c_b.inputs[0]) 454 | links.new(tangent,c_b.inputs[1]) 455 | 456 | d_t = nodes.new(type = 'ShaderNodeVectorMath') 457 | d_b = nodes.new(type = 'ShaderNodeVectorMath') 458 | d_n = nodes.new(type = 'ShaderNodeVectorMath') 459 | d_t.operation = 'DOT_PRODUCT' 460 | d_b.operation = 'DOT_PRODUCT' 461 | d_n.operation = 'DOT_PRODUCT' 462 | links.new(tangent, d_t.inputs[0]) 463 | links.new(binormal,d_b.inputs[0]) 464 | links.new(normal, d_n.inputs[0]) 465 | links.new(bump_normal,d_t.inputs[1]) 466 | links.new(bump_normal,d_b.inputs[1]) 467 | links.new(bump_normal,d_n.inputs[1]) 468 | 469 | xyz = nodes.new(type = 'ShaderNodeCombineXYZ') 470 | links.new(d_t.outputs[1], xyz.inputs[0]) 471 | links.new(d_b.outputs[1], xyz.inputs[1]) 472 | links.new(d_n.outputs[1], xyz.inputs[2]) 473 | final_normal_socket = xyz.outputs[0] 474 | else: 475 | w2o = nodes.new(type = 'ShaderNodeVectorTransform') 476 | w2o.vector_type = 'NORMAL' 477 | w2o.convert_from = 'WORLD' 478 | w2o.convert_to = 'OBJECT' 479 | links.new(bump_normal,w2o.inputs[0]) 480 | final_normal_socket = w2o.outputs[0] 481 | add = nodes.new(type = 'ShaderNodeMixRGB') 482 | div = nodes.new(type = 'ShaderNodeMixRGB') 483 | gam = nodes.new(type = 'ShaderNodeGamma') 484 | emt = nodes.new(type = 'ShaderNodeEmission') 485 | out = nodes.new(type = 'ShaderNodeOutputMaterial') 486 | add.blend_type = 'ADD' 487 | div.blend_type = 'DIVIDE' 488 | add.inputs[0].default_value = 1 489 | div.inputs[0].default_value = 1 490 | add.inputs[2].default_value = 1,1,1,1 491 | div.inputs[2].default_value = 2,2,2,1 492 | gam.inputs[1].default_value = 2.2 493 | emt.inputs[1].default_value = 1 494 | links.new(final_normal_socket, add.inputs[1]) 495 | links.new(add.outputs[0], div.inputs[1]) 496 | links.new(div.outputs[0], gam.inputs[0]) 497 | links.new(gam.outputs[0], emt.inputs[0]) 498 | links.new(emt.outputs[0], out.inputs[0]) 499 | 500 | dst = nodes.new(type = 'ShaderNodeTexImage') # Destination Image 501 | dst.image = dst_image 502 | for node in nodes: 503 | node.select = False 504 | dst.select = True 505 | nodes.active = dst 506 | 507 | return mat 508 | 509 | def generate_mat(self,name): 510 | new_mat = bpy.data.materials.new(name+'_BAKED') 511 | self.add_texs(name,new_mat) 512 | if bpy.context.scene.render.engine == 'CYCLES': 513 | new_mat.use_nodes = True 514 | else: 515 | new_mat.use_nodes = False 516 | return new_mat 517 | 518 | def add_texs(self,name,mat): 519 | ######################### BI materials ##################################### 520 | if self.BAKED_texture: 521 | slot = mat.texture_slots.add() 522 | slot.texture = bpy.data.textures.new(name+'_D',type = 'IMAGE') 523 | slot.texture.image = self.BAKED_texture.image 524 | slot.texture_coords = 'UV' 525 | if self.BAKED_normal: 526 | slot = mat.texture_slots.add() 527 | slot.texture = bpy.data.textures.new(name+'_N',type = 'IMAGE') 528 | slot.texture.image = self.BAKED_normal.image 529 | slot.texture.use_normal_map = True 530 | slot.use_map_color_diffuse = False 531 | slot.use_map_normal = True 532 | slot.normal_map_space = self.BAKED_normal.item.normal_space 533 | slot.texture_coords = 'UV' 534 | if self.BAKED_ambient: 535 | slot = mat.texture_slots.add() 536 | slot.texture = bpy.data.textures.new(name+'_AO',type = 'IMAGE') 537 | slot.texture.image = self.BAKED_ambient.image 538 | slot.blend_type = 'MULTIPLY' 539 | slot.texture_coords = 'UV' 540 | if self.BAKED_glossy: 541 | slot = mat.texture_slots.add() 542 | slot.texture = bpy.data.textures.new(name+'_S',type = 'IMAGE') 543 | slot.texture.image = self.BAKED_glossy.image 544 | slot.use_map_color_diffuse = False 545 | slot.use_map_color_spec = True 546 | slot.texture_coords = 'UV' 547 | if self.BAKED_full: 548 | for slot in mat.texture_slots: 549 | if slot: 550 | slot.use = False 551 | slot = mat.texture_slots.add() 552 | slot.texture = bpy.data.textures.new(name+'_F',type = 'IMAGE') 553 | slot.texture.image = self.BAKED_full.image 554 | mat.use_shadeless = True 555 | slot.texture_coords = 'UV' 556 | if self.BAKED_alpha: 557 | slot = mat.texture_slots.add() 558 | slot.texture = bpy.data.textures.new(name+'_A',type = 'IMAGE') 559 | slot.texture.image = self.BAKED_alpha.image 560 | slot.use_map_color_diffuse = False 561 | slot.use_map_alpha = True 562 | mat.use_transparency = True 563 | mat.alpha = 0 564 | mat.specular_alpha = 0 565 | slot.texture_coords = 'UV' 566 | 567 | ######################### CYCLES materials ################################# 568 | mat.use_nodes = True 569 | nodes = mat.node_tree.nodes 570 | links = mat.node_tree.links 571 | for node in nodes: 572 | nodes.remove(node) 573 | 574 | out = nodes.new(type = 'ShaderNodeOutputMaterial') 575 | out.location = 0,0 576 | pbr = nodes.new(type = 'ShaderNodeBsdfPrincipled') 577 | pbr.location = -200,400 578 | links.new(pbr.outputs[0],out.inputs[0]) 579 | uvm = nodes.new(type = 'ShaderNodeTexCoord') 580 | uvm.location = -1500,400 581 | 582 | if self.BAKED_texture: 583 | imgNode = nodes.new(type = 'ShaderNodeTexImage') 584 | imgNode.location = -600,600 585 | imgNode.image = self.BAKED_texture.image 586 | links.new(imgNode.outputs[0],pbr.inputs[0]) 587 | links.new(uvm.outputs[2],imgNode.inputs[0]) 588 | if self.BAKED_normal: 589 | imgNode = nodes.new(type = 'ShaderNodeTexImage') 590 | imgNode.location = -600,-400 591 | imgNode.image = self.BAKED_normal.image 592 | imgNode.color_space = 'NONE' 593 | nmNode = nodes.new(type = 'ShaderNodeNormalMap') 594 | nmNode.location = -400,-200 595 | nmNode.space = self.BAKED_normal.item.normal_space 596 | if self.BAKED_normal.engine == 'BI' and self.BAKED_normal.item.normal_space == 'OBJECT': 597 | nmNode.space = 'BLENDER_OBJECT' 598 | links.new(imgNode.outputs[0],nmNode.inputs[1]) 599 | links.new(nmNode.outputs[0],pbr.inputs[17]) 600 | links.new(uvm.outputs[2],imgNode.inputs[0]) 601 | if self.BAKED_ambient: 602 | imgNode = nodes.new(type = 'ShaderNodeTexImage') 603 | imgNode.location = -600,200 604 | imgNode.image = self.BAKED_ambient.image 605 | mul = nodes.new(type = 'ShaderNodeMixRGB') 606 | mul.location = -400,400 607 | mul.blend_type = 'MULTIPLY' 608 | mul.inputs[0].default_value = 1 609 | mul.inputs[1].default_value = 1,1,1,1 610 | mul.inputs[2].default_value = 1,1,1,1 611 | diff_socket = None 612 | if len(pbr.inputs[0].links): 613 | diff_socket = pbr.inputs[0].links[0].from_socket 614 | links.new(mul.outputs[0],pbr.inputs[0]) 615 | links.new(imgNode.outputs[0],mul.inputs[2]) 616 | links.new(uvm.outputs[2],imgNode.inputs[0]) 617 | if diff_socket is not None: 618 | links.new(diff_socket,mul.inputs[1]) 619 | if self.BAKED_glossy: 620 | imgNode = nodes.new(type = 'ShaderNodeTexImage') 621 | imgNode.location = -400,0 622 | imgNode.image = self.BAKED_glossy.image 623 | links.new(imgNode.outputs[0],pbr.inputs[5]) 624 | links.new(uvm.outputs[2],imgNode.inputs[0]) 625 | if self.BAKED_full: 626 | imgNode = nodes.new(type = 'ShaderNodeTexImage') 627 | imgNode.location = -600,1000 628 | imgNode.image = self.BAKED_full.image 629 | EmitNode = nodes.new(type = 'ShaderNodeEmission') 630 | EmitNode.location = -200,600 631 | links.new(imgNode.outputs[0],EmitNode.inputs[0]) 632 | links.new(EmitNode.outputs[0],out.inputs[0]) 633 | links.new(uvm.outputs[2],imgNode.inputs[0]) 634 | if self.BAKED_alpha: 635 | if len(out.inputs[0].links): 636 | from_socket = out.inputs[0].links[0].from_socket 637 | transparent = nodes.new(type = 'ShaderNodeBsdfTransparent') 638 | transparent.location = -200, -100 639 | imgNode = nodes.new(type = 'ShaderNodeTexImage') 640 | imgNode.location = -200, -200 641 | imgNode.image = self.BAKED_alpha.image 642 | mix_shader = nodes.new(type = 'ShaderNodeMixShader') 643 | mix_shader.location = out.location[:] 644 | out.location[0] += 200 645 | links.new(imgNode.outputs[0], mix_shader.inputs[0]) 646 | links.new(transparent.outputs[0], mix_shader.inputs[1]) 647 | links.new(from_socket, mix_shader.inputs[2]) 648 | links.new(mix_shader.outputs[0], out.inputs[0]) 649 | links.new(uvm.outputs[2], imgNode.inputs[0]) 650 | mat.game_settings.alpha_blend = 'ALPHA' 651 | 652 | ###### Custom Passes{ 653 | node_y_shift = 500 654 | for baker in self.BAKED_passes: 655 | ####### Find Pass Input Socket{ 656 | pass_input = None 657 | passes = baker.item.pass_name.split('|') 658 | for Pass in passes: 659 | pass_input = pbr.inputs.get(Pass) 660 | if pass_input: break 661 | if pass_input: 662 | if len(pass_input.links)==0: 663 | node_x_shift = -800 664 | pass_input_shift = pass_input 665 | if baker.item.pass_multiplier != 1: 666 | multiplier = baker.item.pass_multiplier 667 | mul = nodes.new(type = 'ShaderNodeMixRGB') 668 | mul.location = node_x_shift,node_y_shift 669 | mul.inputs[0].default_value = 1 670 | mul.blend_type = 'DIVIDE' 671 | mul.inputs[2].default_value = multiplier,multiplier,multiplier,multiplier 672 | links.new(mul.outputs[0],pass_input_shift) 673 | pass_input_shift = mul.inputs[1] 674 | node_x_shift -= 200 675 | if baker.item.pass_addend != 0: 676 | addend = baker.item.pass_addend 677 | add = nodes.new(type = 'ShaderNodeMixRGB') 678 | add.location = node_x_shift,node_y_shift 679 | add.inputs[0].default_value = 1 680 | if addend >= 0: 681 | add.blend_type = 'SUBTRACT' 682 | add.inputs[2].default_value = addend,addend,addend,addend 683 | else: 684 | add.blend_type = 'ADD' 685 | add.inputs[2].default_value = -addend,-addend,-addend,-addend 686 | links.new(add.outputs[0],pass_input_shift) 687 | pass_input_shift = add.inputs[1] 688 | node_x_shift -= 200 689 | imgNode = nodes.new(type = 'ShaderNodeTexImage') 690 | imgNode.location = node_x_shift,node_y_shift 691 | imgNode.image = baker.image 692 | links.new(imgNode.outputs[0],pass_input_shift) 693 | links.new(uvm.outputs[2],imgNode.inputs[0]) 694 | node_y_shift -= 350 695 | ####### } 696 | ###### } 697 | 698 | ####################################################################################### 699 | 700 | def get_file_extension(self,format): 701 | extension = '' 702 | if format == 'PNG': 703 | extension = '.png' 704 | if format == 'JPEG': 705 | extension = '.jpg' 706 | if format == 'TARGA': 707 | extension = '.tar' 708 | if format == 'TIFF': 709 | extension = '.tiff' 710 | if format == 'BMP': 711 | extension = '.bmp' 712 | return extension 713 | 714 | def save_image(self,context,image,settings): 715 | if settings: 716 | img_settings = context.scene.render.image_settings 717 | img_settings.file_format = settings.format 718 | if settings.format == 'PNG': 719 | img_settings.color_mode = settings.channels3 720 | img_settings.compression = settings.compression 721 | img_settings.color_depth = settings.c_depth 722 | if settings.format == 'JPEG': 723 | img_settings.color_mode = settings.channels2 724 | img_settings.quality = settings.quality 725 | if settings.format == 'TARGA': 726 | img_settings.color_mode = settings.channels3 727 | if settings.format == 'TIFF': 728 | img_settings.color_mode = settings.channels3 729 | img_settings.tiff_codec = settings.tiff_codec 730 | img_settings.color_depth = settings.c_depth 731 | 732 | try: 733 | image.save() 734 | image.save_render(image.filepath,context.scene) 735 | except: 736 | self.report(type = {'ERROR'}, 737 | message = 'Could Not Save '+image.name+' to '+image.filepath) 738 | self.running = False 739 | 740 | ####################################################################################### 741 | def check_passes_enabled(self,settings,direct,indirect,color,combined): 742 | enabled = False 743 | if direct: 744 | if settings.use_pass_direct: 745 | enabled = True 746 | if indirect: 747 | if settings.use_pass_indirect: 748 | enabled = True 749 | if color: 750 | if settings.use_pass_color: 751 | enabled = True 752 | if not enabled: 753 | return False 754 | 755 | if combined: 756 | enabled = False 757 | if settings.use_pass_diffuse: 758 | enabled = True 759 | if settings.use_pass_glossy: 760 | enabled = True 761 | if settings.use_pass_transmission: 762 | enabled = True 763 | if settings.use_pass_subsurface: 764 | enabled = True 765 | if settings.use_pass_ambient_occlusion: 766 | enabled = True 767 | if settings.use_pass_emit: 768 | enabled = True 769 | if not enabled: 770 | return False 771 | return True 772 | ####################################################################################### 773 | 774 | def bake(self,context,obj_list,name,s_to_a): 775 | if self.bake_sub_step == 0 or self.bake_sub_step == 10: 776 | while True: 777 | if self.bake_item_id >= len(context.scene.BakeLabMapColl): 778 | return True 779 | bake_item = context.scene.BakeLabMapColl[self.bake_item_id] 780 | if bake_item.enabled: 781 | self.bake_sub_step = 1 782 | break 783 | self.bake_item_id += 1 784 | else: 785 | bake_item = context.scene.BakeLabMapColl[self.bake_item_id] 786 | 787 | props = context.scene.BakeLabProps 788 | #### Final Variables{ 789 | final_name = bake_item.img_name.replace('*',name) 790 | final_samples = bake_item.samples * self.sample_scale 791 | if self.override_image_size: 792 | final_image_width = self.override_image_width * props.aa_samples 793 | final_image_height = self.override_image_height * props.aa_samples 794 | else: 795 | final_image_width = bake_item.width * self.image_scale * props.aa_samples 796 | final_image_height = bake_item.height * self.image_scale * props.aa_samples 797 | #### } 798 | if not self.img_cancelled and self.bake_sub_step >= 0: 799 | last_baked_image = self.current_image 800 | self.current_image = bpy.data.images.new(final_name, 801 | width = final_image_width, height = final_image_height) 802 | self.current_image.filepath = props.out_path + \ 803 | self.current_image.name + \ 804 | self.get_file_extension(bake_item.format) 805 | self.current_image.file_format = bake_item.format 806 | 807 | ######################################################################## 808 | if not self.img_cancelled: 809 | self.new_bake_sub_step = 0 810 | self.new_use_s_to_a = s_to_a 811 | if bake_item.engine == 'CYCLES': 812 | bpy.context.scene.render.engine = 'CYCLES' 813 | for obj in obj_list: 814 | for slot in obj.material_slots: 815 | mat = slot.material 816 | if not mat: continue 817 | mat.use_nodes = True 818 | if s_to_a: 819 | active_obj = context.scene.objects.active 820 | self.createTmpImageNodes(active_obj,self.current_image) 821 | else: 822 | for obj in obj_list: 823 | self.createTmpImageNodes(obj,self.current_image) 824 | 825 | bake_settings = context.scene.render.bake 826 | bake_settings.use_pass_direct = bake_item.cycles_direct 827 | bake_settings.use_pass_indirect = bake_item.cycles_indirect 828 | bake_settings.use_pass_color = bake_item.cycles_color 829 | 830 | if bake_item.type == 'Full': 831 | bake_settings.use_pass_diffuse = bake_item.cycles_diffuse 832 | bake_settings.use_pass_glossy = bake_item.cycles_glossy 833 | bake_settings.use_pass_transmission = bake_item.cycles_transmission 834 | bake_settings.use_pass_subsurface = bake_item.cycles_subsurface 835 | bake_settings.use_pass_ambient_occlusion = bake_item.cycles_ambient_occlusion 836 | bake_settings.use_pass_emit = bake_item.cycles_emit 837 | if not self.check_passes_enabled(bake_settings,True,True,False,True): 838 | self.report(type = {'ERROR'}, 839 | message = 'Nothing to bake to '+final_name) 840 | self.bake_sub_step = 0 841 | self.bake_item_id += 1 842 | return False 843 | texture_type = 'COMBINED' 844 | elif bake_item.type == 'Diffuse': 845 | if not self.check_passes_enabled(bake_settings,True,True,True,False): 846 | self.report(type = {'ERROR'}, 847 | message = 'Nothing to bake to '+final_name) 848 | self.bake_sub_step = 0 849 | self.bake_item_id += 1 850 | return False 851 | texture_type = 'DIFFUSE' 852 | elif bake_item.type == 'Specular': 853 | if not self.check_passes_enabled(bake_settings,True,True,True,False): 854 | self.report(type = {'ERROR'}, 855 | message = 'Nothing to bake to '+final_name) 856 | self.bake_sub_step = 0 857 | self.bake_item_id += 1 858 | return False 859 | texture_type = 'GLOSSY' 860 | elif bake_item.type == 'Alpha': 861 | if not self.check_passes_enabled(bake_settings,True,True,True,False): 862 | self.report(type = {'ERROR'}, 863 | message = 'Nothing to bake to '+final_name) 864 | self.bake_sub_step = 0 865 | self.bake_item_id += 1 866 | return False 867 | texture_type = 'TRANSMISSION' 868 | elif bake_item.type == 'Subsurface': 869 | if not self.check_passes_enabled(bake_settings,True,True,True,False): 870 | self.report(type = {'ERROR'}, 871 | message = 'Nothing to bake to '+final_name) 872 | self.bake_sub_step = 0 873 | self.bake_item_id += 1 874 | return False 875 | texture_type = 'SUBSURFACE' 876 | elif bake_item.type == 'Emission': texture_type = 'EMIT' 877 | elif bake_item.type == 'Ambient': texture_type = 'AO' 878 | elif bake_item.type == 'Shadow': texture_type = 'SHADOW' 879 | elif bake_item.type == 'UV': texture_type = 'UV' 880 | elif bake_item.type == 'Environment': texture_type = 'ENVIRONMENT' 881 | elif bake_item.type == 'Normal': 882 | if bake_item.tricky: 883 | texture_type = 'EMIT' 884 | ################################################# 885 | if self.bake_sub_step == 1: 886 | self.original_mats = [] 887 | self.old_active_render_uvs = [] 888 | self.current_image.name = 'TMP_WORLD_NORMAL_' + self.current_image.name 889 | self.current_image.filepath = props.out_path + \ 890 | self.current_image.name + \ 891 | self.get_file_extension(bake_item.format) 892 | for obj in obj_list: 893 | if s_to_a: 894 | if obj == context.scene.objects.active: 895 | continue 896 | active_render_uv = None 897 | for uv in obj.data.uv_textures: 898 | if uv.active_render: 899 | active_render_uv = uv 900 | self.old_active_render_uvs.append(active_render_uv) 901 | for slot in obj.material_slots: 902 | self.original_mats.append(slot.material) 903 | slot.material = slot.material.copy() 904 | 905 | for obj in obj_list: 906 | if s_to_a: 907 | if obj == context.scene.objects.active: 908 | continue 909 | self.normals_to_emit_node(obj) 910 | self.new_bake_sub_step = 2 911 | ################################################# 912 | elif self.bake_sub_step == 2: 913 | self.trash_imgs.append(last_baked_image) 914 | transfer_mat = self.create_normal_transfer_material(last_baked_image, 915 | self.current_image,bake_item.normal_space) 916 | if s_to_a: 917 | self.new_use_s_to_a = False 918 | active_obj = context.scene.objects.active 919 | for obj in obj_list: 920 | if obj != active_obj: 921 | obj.select = False 922 | active_obj.data.uv_textures.active.active_render = True 923 | for slot in active_obj.material_slots: 924 | tmp_mat = slot.material 925 | slot.material = transfer_mat 926 | self.trash_mats.append(tmp_mat) 927 | else: 928 | for obj in obj_list: 929 | obj.data.uv_textures.active.active_render = True 930 | for slot in obj.material_slots: 931 | tmp_mat = slot.material 932 | slot.material = transfer_mat 933 | self.trash_mats.append(tmp_mat) 934 | self.new_bake_sub_step = -1 935 | ################################################# 936 | elif self.bake_sub_step == -1: 937 | for uv in self.old_active_render_uvs: 938 | if uv: 939 | uv.active_render = True 940 | i = 0 941 | for obj in obj_list: 942 | obj.select = True 943 | if s_to_a: 944 | if obj == context.scene.objects.active: 945 | continue 946 | for slot in obj.material_slots: 947 | tmp_mat = slot.material 948 | slot.material = self.original_mats[i] 949 | self.trash_mats.append(tmp_mat) 950 | i += 1 951 | self.new_bake_sub_step = 10 952 | else: 953 | context.scene.render.bake.normal_space = bake_item.normal_space 954 | texture_type = 'NORMAL' 955 | elif bake_item.type in {'Texture','Passes'}: 956 | texture_type = 'EMIT' 957 | ################################################# 958 | if self.bake_sub_step == 1: 959 | self.original_mats = [] 960 | for obj in obj_list: 961 | if s_to_a: 962 | if obj == context.scene.objects.active: 963 | continue 964 | for slot in obj.material_slots: 965 | self.original_mats.append(slot.material) 966 | slot.material = slot.material.copy() 967 | 968 | for obj in obj_list: 969 | if s_to_a: 970 | if obj == context.scene.objects.active: 971 | continue 972 | if bake_item.type == 'Texture': 973 | self.passes_to_emit_node(obj,['Color','Base Color','Paint Color'],1,0) 974 | else: 975 | self.passes_to_emit_node(obj,bake_item.pass_name.split('|'), 976 | bake_item.pass_multiplier,bake_item.pass_addend) 977 | self.new_bake_sub_step = -1 978 | ################################################# 979 | elif self.bake_sub_step == -1: 980 | i = 0 981 | for obj in obj_list: 982 | obj.select = True 983 | if s_to_a: 984 | if obj == context.scene.objects.active: 985 | continue 986 | for slot in obj.material_slots: 987 | tmp_mat = slot.material 988 | slot.material = self.original_mats[i] 989 | self.trash_mats.append(tmp_mat) 990 | i += 1 991 | self.new_bake_sub_step = 10 992 | else: 993 | self.report(type = {'ERROR'}, 994 | message = 'Unknown Bake Type: '+bake_item.type) 995 | self.bake_sub_step = 0 996 | self.bake_item_id += 1 997 | return False 998 | else:##################################################################### 999 | bpy.context.scene.render.engine = 'BLENDER_RENDER' 1000 | for obj in obj_list: 1001 | for slot in obj.material_slots: 1002 | mat = slot.material 1003 | if not mat: continue 1004 | mat.use_nodes = False 1005 | if s_to_a: 1006 | active_obj = context.scene.objects.active 1007 | for slot in active_obj.material_slots: 1008 | slot.material.use_nodes = False 1009 | for d in active_obj.data.uv_textures.active.data: 1010 | d.image = self.current_image 1011 | else: 1012 | for obj in obj_list: 1013 | for slot in obj.material_slots: 1014 | slot.material.use_nodes = False 1015 | for d in obj.data.uv_textures.active.data: 1016 | d.image = self.current_image 1017 | if bake_item.type == 'Full': texture_type = 'FULL' 1018 | elif bake_item.type == 'Texture': texture_type = 'TEXTURE' 1019 | elif bake_item.type == 'Normal': 1020 | context.scene.render.bake_normal_space = bake_item.normal_space 1021 | texture_type = 'NORMALS' 1022 | elif bake_item.type == 'Ambient': 1023 | if not context.scene.world: 1024 | self.report(type = {'ERROR'},message = 'No Active World') 1025 | self.bake_sub_step = 0 1026 | self.bake_item_id += 1 1027 | return False 1028 | context.scene.render.use_bake_normalize = bake_item.normalize 1029 | texture_type = 'AO' 1030 | elif bake_item.type == 'Shadow': texture_type = 'SHADOW' 1031 | elif bake_item.type == 'Glossy': 1032 | if bake_item.gloss_type == 'SPECULAR': 1033 | if bake_item.gloss_data == 'INTENSITY': 1034 | texture_type = 'SPEC_INTENSITY' 1035 | else: 1036 | texture_type = 'SPEC_COLOR' 1037 | else: 1038 | if bake_item.gloss_data == 'INTENSITY': 1039 | texture_type = 'MIRROR_INTENSITY' 1040 | else: 1041 | texture_type = 'MIRROR_COLOR' 1042 | elif bake_item.type == 'Emission': texture_type = 'EMIT' 1043 | elif bake_item.type == 'Alpha': texture_type = 'ALPHA' 1044 | elif bake_item.type == 'Displacement': 1045 | context.scene.render.use_bake_normalize = bake_item.normalize 1046 | texture_type = 'DISPLACEMENT' 1047 | elif bake_item.type == 'Derivative': texture_type = 'DERIVATIVE' 1048 | elif bake_item.type == 'Vertex Col': texture_type = 'VERTEX_COLORS' 1049 | else: 1050 | self.report(type = {'ERROR'}, 1051 | message = 'Unknown Bake Type: '+bake_item.type) 1052 | self.bake_sub_step = 0 1053 | self.bake_item_id += 1 1054 | return False 1055 | ############################################################################## 1056 | 1057 | if self.bake_sub_step >= 0: 1058 | self.current_tex_baker = baker(texture_type, self.current_image, bake_item, 1059 | bake_item.engine, final_samples) 1060 | if props.save_or_pack == 'SAVE': 1061 | self.save_image(context,self.current_tex_baker.image,bake_item) 1062 | if not self.running: return False 1063 | else: 1064 | self.current_tex_baker.image.pack(True) 1065 | self.img_cancelled = False 1066 | s_to_a = self.new_use_s_to_a 1067 | 1068 | 1069 | if s_to_a: 1070 | context.scene.render.use_bake_selected_to_active = True 1071 | context.scene.render.bake.use_selected_to_active = True 1072 | else: 1073 | context.scene.render.use_bake_selected_to_active = False 1074 | context.scene.render.bake.use_selected_to_active = False 1075 | 1076 | if self.bake_sub_step >= 0: 1077 | if not self.current_tex_baker.bake(): 1078 | self.img_cancelled = True 1079 | return False 1080 | 1081 | self.bake_sub_step = self.new_bake_sub_step 1082 | if self.bake_sub_step == 0 or self.bake_sub_step == 10: 1083 | self.bake_item_id += 1 1084 | 1085 | if bake_item.type == 'Full': 1086 | self.BAKED_full = self.current_tex_baker 1087 | if bake_item.type == 'Texture': 1088 | self.BAKED_texture = self.current_tex_baker 1089 | elif bake_item.type == 'Normal': 1090 | self.BAKED_normal = self.current_tex_baker 1091 | elif bake_item.type == 'Ambient': 1092 | self.BAKED_ambient = self.current_tex_baker 1093 | elif bake_item.type == 'Glossy': 1094 | self.BAKED_glossy = self.current_tex_baker 1095 | elif bake_item.type == 'Alpha': 1096 | self.BAKED_alpha = self.current_tex_baker 1097 | elif bake_item.type == 'Passes': 1098 | self.BAKED_passes.append( self.current_tex_baker ) 1099 | 1100 | return False 1101 | 1102 | ####################################################################################### 1103 | 1104 | def merge_objects(self,context,obj_list): 1105 | merged_mesh = bpy.data.meshes.new('BAKELAB_MERGED_MESH_TMP') 1106 | merged_obj = bpy.data.objects.new('BAKELAB_MERGED_OBJ_TMP', merged_mesh) 1107 | merged_obj.location = 0,0,0 1108 | context.scene.objects.link(merged_obj) 1109 | merged_mesh.update() 1110 | 1111 | for obj in obj_list: 1112 | if obj.type != 'MESH': 1113 | continue 1114 | 1115 | bpy.ops.object.select_all(action='DESELECT') 1116 | obj.select = True 1117 | context.scene.objects.active = obj 1118 | bpy.ops.object.duplicate(linked=False, mode='TRANSLATION') 1119 | obj_clone = context.scene.objects.active 1120 | 1121 | while len(obj_clone.vertex_groups): 1122 | obj_clone.vertex_groups.remove(obj_clone.vertex_groups[0]) 1123 | v_group = obj_clone.vertex_groups.new(name = obj.name) 1124 | v_group.add(list(range(len(obj_clone.data.vertices))),weight = 1,type = 'ADD') 1125 | 1126 | bpy.ops.object.select_all(action='DESELECT') 1127 | merged_obj.select = True 1128 | obj_clone.select = True 1129 | context.scene.objects.active = merged_obj 1130 | clone_data = obj_clone.data 1131 | bpy.ops.object.join() 1132 | bpy.data.meshes.remove(clone_data) 1133 | 1134 | return merged_obj 1135 | 1136 | def separate_objects_and_merge_with_modifier(self,context,merged_obj,obj_list): 1137 | new_merged_mesh = bpy.data.meshes.new('BAKELAB_NEW_MERGED_MESH_TMP') 1138 | new_merged_obj = bpy.data.objects.new('BAKELAB_NEW_MERGED_OBJ_TMP', new_merged_mesh) 1139 | new_merged_obj.location = 0,0,0 1140 | context.scene.objects.link(new_merged_obj) 1141 | new_merged_mesh.update() 1142 | 1143 | for obj in obj_list: 1144 | if obj.type != 'MESH': 1145 | continue 1146 | ##### Copy UV layers From Merged Object To Original Objects{ 1147 | if context.scene.BakeLabProps.newuv or not obj.data.uv_textures.active: 1148 | bpy.ops.object.select_all(action='DESELECT') 1149 | merged_obj.select = True 1150 | context.scene.objects.active = merged_obj 1151 | 1152 | bpy.ops.object.mode_set(mode='EDIT') 1153 | bpy.ops.mesh.select_all(action='DESELECT') 1154 | merged_obj.vertex_groups.active_index = merged_obj.vertex_groups[obj.name].index 1155 | bpy.ops.object.vertex_group_select() 1156 | bpy.ops.mesh.separate(type='SELECTED') 1157 | bpy.ops.object.mode_set(mode='OBJECT', toggle=False) 1158 | 1159 | for s_obj in context.selected_objects: 1160 | if s_obj != merged_obj: 1161 | separated_obj = s_obj 1162 | 1163 | bpy.ops.object.select_all(action='DESELECT') 1164 | separated_obj.select = True 1165 | obj.select = True 1166 | context.scene.objects.active = separated_obj 1167 | new_uv = obj.data.uv_textures.new('UVMap_BAKELAB') 1168 | obj.data.uv_textures.active = new_uv 1169 | bpy.ops.object.join_uvs() 1170 | obj.data.update() 1171 | 1172 | separated_data = separated_obj.data 1173 | bpy.data.objects.remove(separated_obj) 1174 | bpy.data.meshes.remove(separated_data) 1175 | ##### } 1176 | 1177 | ##### Create New Merged Object{ 1178 | bpy.ops.object.select_all(action='DESELECT') 1179 | obj.select = True 1180 | context.scene.objects.active = obj 1181 | bpy.ops.object.duplicate(linked=False, mode='TRANSLATION') 1182 | obj_clone = context.scene.objects.active 1183 | 1184 | ########## Apply modifiers{ 1185 | for modifier in obj_clone.modifiers: 1186 | if modifier.show_render: 1187 | if modifier.type == 'SUBSURF': 1188 | modifier.levels = modifier.render_levels 1189 | bpy.ops.object.modifier_apply(modifier = modifier.name) 1190 | ########## } 1191 | 1192 | ########## Merge{ 1193 | bpy.ops.object.select_all(action='DESELECT') 1194 | new_merged_obj.select = True 1195 | obj_clone.select = True 1196 | context.scene.objects.active = new_merged_obj 1197 | clone_data = obj_clone.data 1198 | bpy.ops.object.join() 1199 | bpy.data.meshes.remove(clone_data) 1200 | ########## } 1201 | ##### } 1202 | 1203 | ##################### Remove Merged Object 1204 | merged_data = merged_obj.data 1205 | bpy.data.objects.remove(merged_obj) 1206 | bpy.data.meshes.remove(merged_data) 1207 | return new_merged_obj 1208 | 1209 | ############################################################################## 1210 | def prepare_next_object(self,context): 1211 | self.BAKED_full = None 1212 | self.BAKED_texture = None 1213 | self.BAKED_normal = None 1214 | self.BAKED_ambient = None 1215 | self.BAKED_glossy = None 1216 | self.BAKED_alpha = None 1217 | self.BAKED_passes = [] 1218 | 1219 | while True: 1220 | if self.bake_obj_id>=len(self.bake_objs): 1221 | self.next(context) 1222 | return 1223 | current_obj = self.bake_objs[self.bake_obj_id] 1224 | self.bake_obj_id+=1 1225 | if current_obj.type=='MESH': 1226 | bpy.ops.object.select_all(action = 'DESELECT') 1227 | current_obj.select = True 1228 | context.scene.objects.active = current_obj 1229 | self.unwrap(context.scene.BakeLabProps,current_obj) 1230 | if self.check_uv_data(context): 1231 | break 1232 | else: 1233 | self.report(type = {'WARNING'},message = 'Cound not unwrap '+current_obj.name) 1234 | 1235 | self.add_empty_mat(current_obj) 1236 | self.tmp_use_nodes = [i.material.use_nodes for i in current_obj.material_slots] 1237 | self.bake_item_id = 0 1238 | self.current_image = None 1239 | self.current_objs.clear() 1240 | self.current_objs.append(current_obj) 1241 | 1242 | ############################################################################## 1243 | 1244 | def check_uv_data(self,context): 1245 | object = context.scene.objects.active 1246 | if not len(object.modifiers): 1247 | if object.data.uv_textures.active: 1248 | return True 1249 | else: 1250 | return False 1251 | 1252 | selected_objects = [obj for obj in context.selected_objects] 1253 | bpy.ops.object.select_all(action='DESELECT') 1254 | object.select = True 1255 | context.scene.objects.active = object 1256 | bpy.ops.object.duplicate(linked=False, mode='TRANSLATION') 1257 | obj_clone = context.scene.objects.active 1258 | 1259 | ########## Apply modifiers{ 1260 | for modifier in obj_clone.modifiers: 1261 | if modifier.show_render: 1262 | if modifier.type == 'SUBSURF': 1263 | modifier.levels = modifier.render_levels 1264 | bpy.ops.object.modifier_apply(modifier = modifier.name) 1265 | ########## } 1266 | 1267 | has_uv = obj_clone.data.uv_textures.active is not None 1268 | 1269 | bpy.ops.object.select_all(action='DESELECT') 1270 | context.scene.objects.active = object 1271 | for obj in selected_objects: 1272 | obj.select = True 1273 | clone_data = obj_clone.data 1274 | bpy.data.objects.remove(obj_clone) 1275 | bpy.data.meshes.remove(clone_data) 1276 | return has_uv 1277 | 1278 | ############################################################################## 1279 | def down_scale(self,img,val): 1280 | if val == 1: return 1281 | img.scale(img.size[0]/val,img.size[1]/val) 1282 | ############################################################################## 1283 | 1284 | def manage_baking(self,context,event): 1285 | scene = context.scene 1286 | props = context.scene.BakeLabProps 1287 | s_to_a = props.s_to_a 1288 | 1289 | if self.current_image: 1290 | if not self.current_image.is_dirty: 1291 | if not self.img_cancelled and \ 1292 | self.bake_sub_step < 10: 1293 | return 1294 | else: 1295 | self.down_scale(self.current_image,props.aa_samples) 1296 | if props.save_or_pack == 'SAVE': 1297 | self.save_image(context,self.current_image,None) 1298 | if not self.running: return 1299 | else: 1300 | self.current_image.pack(True) 1301 | 1302 | if not s_to_a: 1303 | if props.all_in_one: 1304 | bake_cancel = False 1305 | if not len(self.current_objs): 1306 | self.BAKED_full = None 1307 | self.BAKED_texture = None 1308 | self.BAKED_normal = None 1309 | self.BAKED_ambient = None 1310 | self.BAKED_glossy = None 1311 | self.BAKED_alpha = None 1312 | self.BAKED_passes = [] 1313 | 1314 | self.merged_obj = self.merge_objects(context,self.bake_objs) 1315 | self.merged_obj.select = True 1316 | context.scene.objects.active = self.merged_obj 1317 | self.unwrap(context.scene.BakeLabProps,self.merged_obj) 1318 | self.merged_obj = self.separate_objects_and_merge_with_modifier( 1319 | context,self.merged_obj,self.bake_objs) 1320 | scene.objects.active = self.merged_obj 1321 | self.merged_obj.select = True 1322 | bake_cancel = not self.check_uv_data(context) 1323 | 1324 | if not bake_cancel: 1325 | self.current_objs.clear() 1326 | self.tmp_use_nodes = [] 1327 | for obj in self.bake_objs: 1328 | if obj.type != 'MESH': continue 1329 | bpy.ops.object.select_all(action = 'DESELECT') 1330 | obj.select = True 1331 | scene.objects.active = obj 1332 | 1333 | self.current_objs.append(obj) 1334 | self.add_empty_mat(obj) 1335 | for slot in obj.material_slots: 1336 | self.tmp_use_nodes.append(slot.material.use_nodes) 1337 | 1338 | bpy.ops.object.select_all(action = 'DESELECT') 1339 | scene.objects.active = self.merged_obj 1340 | self.merged_obj.select = True 1341 | while len(self.merged_obj.material_slots)>0: 1342 | bpy.ops.object.material_slot_remove() 1343 | self.add_empty_mat(self.merged_obj) 1344 | for obj in self.current_objs: 1345 | obj.select = True 1346 | 1347 | self.current_image = None 1348 | 1349 | if bake_cancel: ##### Cancel 1350 | self.report(type = {'WARNING'},message = 'Cound not unwrap objects') 1351 | ##################### Remove Merged Object 1352 | if self.merged_obj: 1353 | merged_data = self.merged_obj.data 1354 | bpy.data.objects.remove(self.merged_obj) 1355 | bpy.data.meshes.remove(merged_data) 1356 | self.next(context) 1357 | return 1358 | else: ##### Bake 1359 | if self.main_name: output_name = self.main_name 1360 | else: output_name = props.general_name 1361 | 1362 | if self.bake(context,self.current_objs,output_name,True): 1363 | new_mat = None 1364 | if props.gen_mat: 1365 | new_mat = self.generate_mat(output_name) 1366 | i = 0 1367 | for obj in self.current_objs: 1368 | for slot in obj.material_slots: 1369 | slot.material.use_nodes = self.tmp_use_nodes[i] 1370 | i += 1 1371 | ##### Append Material{ 1372 | if props.gen_mat and props.append_mat: 1373 | scene.objects.active = obj 1374 | bpy.ops.object.material_slot_add() 1375 | obj.material_slots[-1].material = new_mat 1376 | ##### } 1377 | 1378 | ##################### Remove Merged Object 1379 | if self.merged_obj: 1380 | merged_data = self.merged_obj.data 1381 | bpy.data.objects.remove(self.merged_obj) 1382 | bpy.data.meshes.remove(merged_data) 1383 | 1384 | self.next(context) 1385 | return 1386 | else: 1387 | if not len(self.current_objs): 1388 | self.prepare_next_object(context) 1389 | if not self.running: return 1390 | if self.bake(context,self.current_objs,self.current_objs[0].name,False): 1391 | self.removeTmpImageNodes(self.current_objs) 1392 | for i in range(len(self.tmp_use_nodes)): 1393 | self.current_objs[0].material_slots[i].material.use_nodes = self.tmp_use_nodes[i] 1394 | 1395 | ##### Generate and Append Material{ 1396 | if props.gen_mat: 1397 | new_mat = self.generate_mat(self.current_objs[0].name) 1398 | if props.append_mat: 1399 | bpy.ops.object.material_slot_add() 1400 | self.current_objs[0].material_slots[-1].material = new_mat 1401 | ##### } 1402 | self.prepare_next_object(context) 1403 | else: 1404 | bake_cancel = False 1405 | if not len(self.current_objs): 1406 | self.BAKED_full = None 1407 | self.BAKED_texture = None 1408 | self.BAKED_normal = None 1409 | self.BAKED_ambient = None 1410 | self.BAKED_glossy = None 1411 | self.BAKED_alpha = None 1412 | self.BAKED_passes = [] 1413 | 1414 | active_obj = scene.objects.active 1415 | self.unwrap(context.scene.BakeLabProps,active_obj) 1416 | bake_cancel = not self.check_uv_data(context) 1417 | 1418 | if not bake_cancel: 1419 | self.current_objs.clear() 1420 | self.tmp_use_nodes = [] 1421 | for obj in self.bake_objs: 1422 | if obj.type != 'MESH': continue 1423 | bpy.ops.object.select_all(action = 'DESELECT') 1424 | obj.select = True 1425 | scene.objects.active = obj 1426 | 1427 | self.current_objs.append(obj) 1428 | self.add_empty_mat(obj) 1429 | for slot in obj.material_slots: 1430 | self.tmp_use_nodes.append(slot.material.use_nodes) 1431 | 1432 | for obj in self.current_objs: 1433 | obj.select = True 1434 | 1435 | scene.objects.active = active_obj 1436 | self.current_image = None 1437 | 1438 | if bake_cancel: 1439 | self.report(type = {'WARNING'},message = 'Cound not unwrap '+scene.objects.active.name) 1440 | self.next(context) 1441 | return 1442 | else: 1443 | if self.main_name: output_name = self.main_name 1444 | else: output_name = scene.objects.active.name 1445 | 1446 | if self.bake(context,self.current_objs,output_name,True): 1447 | i = 0 1448 | for obj in self.current_objs: 1449 | for slot in obj.material_slots: 1450 | slot.material.use_nodes = self.tmp_use_nodes[i] 1451 | i += 1 1452 | 1453 | ##### Generate and Append Material{ 1454 | if props.gen_mat: 1455 | new_mat = self.generate_mat(output_name) 1456 | if props.append_mat: 1457 | bpy.ops.object.material_slot_add() 1458 | scene.objects.active.material_slots[-1].material = new_mat 1459 | ##### } 1460 | 1461 | self.next(context) 1462 | return 1463 | ############################################################################## 1464 | 1465 | def modal(self,context,event): 1466 | if not self.running: 1467 | self.finish(context) 1468 | return {'FINISHED'} 1469 | 1470 | if event.type in {'ESC'}: 1471 | self.finish(context) 1472 | return {'CANCELLED'} 1473 | 1474 | if event.type == 'TIMER': 1475 | self.manage_baking(context,event) 1476 | 1477 | return {'RUNNING_MODAL'} 1478 | 1479 | def init(self): 1480 | self.current_image = None 1481 | self.current_objs = [] 1482 | self.merged_obj = None 1483 | self.bake_obj_id = 0 1484 | self.bake_item_id = 0 1485 | self.running = True 1486 | self.img_cancelled = False 1487 | self.bake_sub_step = 0 1488 | 1489 | self.main_name = None 1490 | self.image_scale = 1.0 1491 | self.override_image_size = False 1492 | self.override_image_width = 1024 1493 | self.override_image_height = 1024 1494 | self.sample_scale = 1.0 1495 | 1496 | def manage_linked_datas(self,context,solution): 1497 | if solution == 'MAKE_SINGLE_USER': 1498 | for obj in context.selected_objects: 1499 | if obj.type != 'MESH': continue 1500 | if obj.data.users>1: 1501 | obj.data = obj.data.copy() 1502 | elif solution == 'EXCLUDE': 1503 | data_list = [] 1504 | active_obj = context.scene.objects.active 1505 | if active_obj: 1506 | if active_obj.type == 'MESH': 1507 | data_list.append(active_obj.data) 1508 | for obj in context.selected_objects: 1509 | if obj.type != 'MESH': continue 1510 | if obj == active_obj: continue 1511 | if obj.data.users>1: 1512 | if obj.data in data_list: 1513 | obj.select = False 1514 | continue 1515 | data_list.append(obj.data) 1516 | 1517 | def execute(self,context): 1518 | self.save_defaults(context) 1519 | props = context.scene.BakeLabProps 1520 | 1521 | self.empty_mat = None 1522 | self.trash_mats = [] 1523 | self.trash_imgs = [] 1524 | self.all_baked_objs = [] 1525 | self.init() 1526 | if props.use_list: 1527 | if not len(context.scene.BakeLabObjColl): 1528 | self.report(type = {'WARNING'},message = 'Add Some Objects to List') 1529 | return {'CANCELLED'} 1530 | 1531 | self.ObjListIndex = 0 1532 | while True: 1533 | if self.ObjListIndex>=len(context.scene.BakeLabObjColl): 1534 | self.report(type = {'WARNING'},message = 'No Objects Found') 1535 | return {'CANCELLED'} 1536 | obj_list = context.scene.BakeLabObjColl[self.ObjListIndex] 1537 | if obj_list.enabled: 1538 | bpy.ops.object.select_all(action='DESELECT') 1539 | for obj in obj_list.objects: 1540 | if obj.object: 1541 | if obj.object.type == 'MESH': 1542 | obj.object.select = True 1543 | context.scene.objects.active = obj_list.active 1544 | if obj_list.active: 1545 | obj_list.active.select = True 1546 | self.manage_linked_datas(context,props.linked_datas) 1547 | 1548 | #### Check Validity of the List{ 1549 | if props.s_to_a: 1550 | if not obj_list.active: 1551 | self.ObjListIndex += 1 1552 | continue 1553 | if obj_list.active.type != 'MESH': 1554 | self.ObjListIndex += 1 1555 | continue 1556 | if len(context.selected_objects)<2: 1557 | self.ObjListIndex += 1 1558 | continue 1559 | 1560 | context.scene.render.bake.use_cage = props.use_cage 1561 | context.scene.render.bake_distance = props.cage_extrusion * obj_list.ray_scale 1562 | context.scene.render.bake.cage_extrusion = props.cage_extrusion * obj_list.ray_scale 1563 | context.scene.render.bake.cage_object = '' 1564 | else: 1565 | if len(context.selected_objects)<1: 1566 | self.ObjListIndex += 1 1567 | continue 1568 | context.scene.render.bake.use_cage = False 1569 | context.scene.render.bake_distance = props.ray_limit * obj_list.ray_scale 1570 | context.scene.render.bake.cage_extrusion = props.ray_limit * obj_list.ray_scale 1571 | #### } 1572 | 1573 | self.main_name = obj_list.name 1574 | self.image_scale = obj_list.image_scale 1575 | self.override_image_size = obj_list.override_size 1576 | self.override_image_width = obj_list.width 1577 | self.override_image_height = obj_list.height 1578 | self.sample_scale = obj_list.sample_scale 1579 | 1580 | self.ObjListIndex += 1 1581 | break 1582 | self.ObjListIndex += 1 1583 | else: 1584 | if len(context.selected_objects)==0: 1585 | self.report(type = {'WARNING'},message = 'Nothing selected') 1586 | return {'CANCELLED'} 1587 | for obj in context.selected_objects: 1588 | if obj.type != 'MESH': 1589 | obj.select = False 1590 | if context.scene.objects.active: 1591 | context.scene.objects.active.select = True 1592 | self.manage_linked_datas(context,props.linked_datas) 1593 | 1594 | if props.s_to_a: 1595 | if len(context.selected_objects)<2: 1596 | self.report(type = {'WARNING'},message = 'Select Two or More Mesh Objects') 1597 | return {'CANCELLED'} 1598 | if not context.scene.objects.active: 1599 | self.report(type = {'WARNING'},message = 'Active Object Not Found') 1600 | return {'CANCELLED'} 1601 | if context.scene.objects.active.type != 'MESH': 1602 | self.report(type = {'WARNING'},message = 'Active Object Is Not a Mesh') 1603 | return {'CANCELLED'} 1604 | context.scene.render.bake.use_cage = props.use_cage 1605 | context.scene.render.bake_distance = props.cage_extrusion 1606 | context.scene.render.bake.cage_extrusion = props.cage_extrusion 1607 | context.scene.render.bake.cage_object = '' 1608 | else: 1609 | context.scene.render.bake.use_cage = False 1610 | context.scene.render.bake_distance = props.ray_limit 1611 | context.scene.render.bake.cage_extrusion = props.ray_limit 1612 | self.bake_objs = [i for i in context.selected_objects] 1613 | if props.s_to_a: 1614 | self.all_baked_objs.append(context.scene.objects.active) 1615 | else: 1616 | self.all_baked_objs.extend(self.bake_objs) 1617 | 1618 | context.scene.cycles.device = props.compute_device 1619 | context.scene.render.bake_margin = props.bake_margin 1620 | context.scene.render.bake.margin = props.bake_margin 1621 | 1622 | wm = context.window_manager 1623 | self._timer = wm.event_timer_add(0.5, context.window) 1624 | self._handle = bpy.types.SpaceView3D.draw_handler_add( 1625 | BakeLab_DrawCallback,(self,context), 1626 | 'WINDOW','POST_PIXEL') 1627 | wm.modal_handler_add(self) 1628 | 1629 | return {'RUNNING_MODAL'} 1630 | 1631 | def next(self,context): 1632 | props = context.scene.BakeLabProps 1633 | if props.use_list: 1634 | while True: 1635 | if self.ObjListIndex>=len(context.scene.BakeLabObjColl): 1636 | break 1637 | obj_list = context.scene.BakeLabObjColl[self.ObjListIndex] 1638 | if obj_list.enabled: 1639 | bpy.ops.object.select_all(action='DESELECT') 1640 | for obj in obj_list.objects: 1641 | if obj.object: 1642 | if obj.object.type == 'MESH': 1643 | obj.object.select = True 1644 | context.scene.objects.active = obj_list.active 1645 | if obj_list.active: 1646 | obj_list.active.select = True 1647 | self.manage_linked_datas(context,props.linked_datas) 1648 | 1649 | #### Check Validity of the List{ 1650 | if props.s_to_a: 1651 | if not obj_list.active: 1652 | self.ObjListIndex += 1 1653 | continue 1654 | if obj_list.active.type != 'MESH': 1655 | self.ObjListIndex += 1 1656 | continue 1657 | if len(context.selected_objects)<2: 1658 | self.ObjListIndex += 1 1659 | continue 1660 | context.scene.render.bake.use_cage = props.use_cage 1661 | context.scene.render.bake_distance = props.cage_extrusion * obj_list.ray_scale 1662 | context.scene.render.bake.cage_extrusion = props.cage_extrusion * obj_list.ray_scale 1663 | context.scene.render.bake.cage_object = '' 1664 | else: 1665 | if len(context.selected_objects)<1: 1666 | self.ObjListIndex += 1 1667 | continue 1668 | context.scene.render.bake.use_cage = False 1669 | context.scene.render.bake_distance = props.ray_limit * obj_list.ray_scale 1670 | context.scene.render.bake.cage_extrusion = props.ray_limit * obj_list.ray_scale 1671 | #### } 1672 | 1673 | self.init() 1674 | self.bake_objs = [i for i in context.selected_objects] 1675 | if props.s_to_a: 1676 | self.all_baked_objs.append(context.scene.objects.active) 1677 | else: 1678 | self.all_baked_objs.extend(self.bake_objs) 1679 | self.main_name = obj_list.name 1680 | self.image_scale = obj_list.image_scale 1681 | self.override_image_size = obj_list.override_size 1682 | self.override_image_width = obj_list.width 1683 | self.override_image_height = obj_list.height 1684 | self.sample_scale = obj_list.sample_scale 1685 | self.ObjListIndex += 1 1686 | return 1687 | self.ObjListIndex += 1 1688 | self.running = False 1689 | 1690 | def finish(self, context): 1691 | props = context.scene.BakeLabProps 1692 | self.running = False 1693 | wm = context.window_manager 1694 | wm.event_timer_remove(self._timer) 1695 | bpy.types.SpaceView3D.draw_handler_remove(self._handle, 'WINDOW') 1696 | 1697 | for obj in self.all_baked_objs: 1698 | if not obj: continue 1699 | if obj.type != 'MESH': continue 1700 | 1701 | if props.gen_mat and props.append_mat: 1702 | if obj.data.uv_textures.active: 1703 | obj.data.uv_textures.active.active_render = True 1704 | ############################## Remove Unused UV Layers{ 1705 | if props.deluvs: 1706 | curr_uv = 0 1707 | uv_texs = obj.data.uv_textures 1708 | uvs_len = len(uv_texs) 1709 | while curr_uv1: 1722 | bpy.ops.object.material_slot_remove() 1723 | #######} 1724 | 1725 | 1726 | self.restore_defaults(context) 1727 | if props.gen_mat and props.append_mat: 1728 | for obj in self.all_baked_objs: 1729 | if obj.type != 'MESH': continue 1730 | for slot in obj.material_slots: 1731 | if slot.material: 1732 | if bpy.context.scene.render.engine == 'CYCLES': 1733 | slot.material.use_nodes = True 1734 | else: 1735 | slot.material.use_nodes = False 1736 | 1737 | ####### Clear Trashes{ 1738 | for mat in self.trash_mats: 1739 | if mat: 1740 | bpy.data.materials.remove(mat) 1741 | for img in self.trash_imgs: 1742 | if img: 1743 | bpy.data.images.remove(img) 1744 | ####### } 1745 | 1746 | ################################################################ 1747 | ################################################################ 1748 | 1749 | class BakeLabAddMapItem(bpy.types.Operator): 1750 | """Add a new bake map""" 1751 | bl_idname = "bakelab.newmapitem" 1752 | bl_label = "Add bake map" 1753 | bl_options = {'REGISTER','UNDO'} 1754 | 1755 | type = bpy.props.EnumProperty( 1756 | name = 'Type', 1757 | items = (('Full', 'Full',''), 1758 | ('Texture', 'Texture',''), 1759 | ('Normal', 'Normal',''), 1760 | ('Ambient', 'Ambient',''), 1761 | ('Shadow', 'Shadow',''), 1762 | ('Glossy', 'Glossy',''), 1763 | ('Emission', 'Emission',''), 1764 | ('Alpha', 'Alpha/Transmission',''), 1765 | ('Displacement','Displacement (BI Only)',''), 1766 | ('Derivative', 'Derivative (BI Only)',''), 1767 | ('Vertex Col', 'Vertex Colors (BI Only)',''), 1768 | ('UV', 'UV (Cycles Only)',''), 1769 | ('Diffuse', 'Diffuse (Cycles Only)',''), 1770 | ('Environment', 'Environment (Cycles Only)',''), 1771 | ('Subsurface', 'Subsurface (Cycles Only)',''), 1772 | ('Passes', 'Custom Passes (Cycles Only)',''))) 1773 | width = bpy.props.IntProperty(name = 'Width',default = 1024, 1774 | min = 1, soft_max = 16384) 1775 | height = bpy.props.IntProperty(name = 'Height',default = 1024, 1776 | min = 1, soft_max = 16384) 1777 | format = bpy.props.EnumProperty( 1778 | name = 'Format', 1779 | items = (('PNG','png',''), 1780 | ('JPEG','jpg',''), 1781 | ('TARGA','tar',''), 1782 | ('TIFF','tiff',''), 1783 | ('BMP','bmp',''))) 1784 | 1785 | def calcItemSettings(self,context,item): 1786 | if context.scene.render.engine == 'CYCLES': 1787 | item.engine = 'CYCLES' 1788 | else: 1789 | item.engine = 'BI' 1790 | 1791 | if self.type == 'Full': 1792 | item.img_name = '*_f' 1793 | if item.engine == 'CYCLES': 1794 | item.samples = 32 1795 | else: 1796 | item.samples = 16 1797 | if self.type == 'Texture': 1798 | item.img_name = '*_t' 1799 | item.samples = 6 1800 | if self.type == 'Normal': 1801 | item.img_name = '*_n' 1802 | item.samples = 6 1803 | if self.type == 'Ambient': 1804 | item.img_name = '*_ao' 1805 | item.normalize = True 1806 | if item.engine == 'CYCLES': 1807 | item.samples = 32 1808 | else: 1809 | item.samples = 16 1810 | if self.type == 'Shadow': 1811 | item.img_name = '*_sh' 1812 | item.samples = 12 1813 | if self.type == 'Displacement': 1814 | item.img_name = '*_h' 1815 | item.normalize = False 1816 | if self.type == 'Glossy': 1817 | item.img_name = '*_s' 1818 | item.samples = 12 1819 | if self.type == 'Diffuse': 1820 | item.img_name = '*_d' 1821 | item.samples = 12 1822 | if self.type == 'Emission': 1823 | item.img_name = '*_e' 1824 | item.samples = 6 1825 | if self.type == 'Alpha': 1826 | item.img_name = '*_a' 1827 | item.samples = 8 1828 | if self.type == 'Derivative': 1829 | item.img_name = '*_dr' 1830 | if self.type == 'Vertex Col': 1831 | item.img_name = '*_vcol' 1832 | if self.type == 'UV': 1833 | item.img_name = '*_uv' 1834 | item.samples = 2 1835 | if self.type == 'Environment': 1836 | item.img_name = '*_env' 1837 | item.samples = 6 1838 | if self.type == 'Subsurface': 1839 | item.img_name = '*_sss' 1840 | item.samples = 32 1841 | if self.type == 'Passes': 1842 | item.img_name = '*_pass' 1843 | item.samples = 6 1844 | 1845 | def execute(self,context): 1846 | context.area.tag_redraw() 1847 | item = context.scene.BakeLabMapColl.add() 1848 | item.type = self.type 1849 | item.width = self.width 1850 | item.height = self.height 1851 | item.format = self.format 1852 | self.calcItemSettings(context,item) 1853 | context.scene.BakeLabMapListIndex=len(context.scene.BakeLabMapColl)-1 1854 | return {'FINISHED'} 1855 | 1856 | def invoke(self, context, event): 1857 | wm = context.window_manager 1858 | return wm.invoke_props_dialog(self) 1859 | 1860 | class BakeLabRemoveMapItem(bpy.types.Operator): 1861 | """Remove selected bake map""" 1862 | bl_idname = "bakelab.removemapitem" 1863 | bl_label = "remove bake map" 1864 | bl_options = {'REGISTER','UNDO'} 1865 | 1866 | @classmethod 1867 | def poll(cls,context): 1868 | return context.scene.BakeLabMapColl 1869 | 1870 | def execute(self,context): 1871 | context.area.tag_redraw() 1872 | context.scene.BakeLabMapColl.remove(context.scene.BakeLabMapListIndex) 1873 | context.scene.BakeLabMapListIndex = max(context.scene.BakeLabMapListIndex - 1,0) 1874 | context.scene.BakeLabMapListIndex = min(context.scene.BakeLabMapListIndex,len(context.scene.BakeLabMapColl)) 1875 | return {'FINISHED'} 1876 | 1877 | ################################################################ 1878 | 1879 | class BakeLabAddObjItem(bpy.types.Operator): 1880 | """Add a new bake object list""" 1881 | bl_idname = "bakelab.newobjitem" 1882 | bl_label = "Add bake object list" 1883 | bl_options = {'REGISTER','UNDO'} 1884 | name = bpy.props.StringProperty(name = 'Group Name',default = 'Group') 1885 | 1886 | def execute(self,context): 1887 | context.area.tag_redraw() 1888 | item = context.scene.BakeLabObjColl.add() 1889 | item.name = self.name 1890 | item.active = context.scene.objects.active 1891 | for obj in context.selected_objects: 1892 | item.objects.add().object = obj 1893 | context.scene.BakeLabMapListIndex=len(context.scene.BakeLabMapColl)-1 1894 | return {'FINISHED'} 1895 | 1896 | def invoke(self, context, event): 1897 | wm = context.window_manager 1898 | return wm.invoke_props_dialog(self) 1899 | 1900 | class BakeLabRemoveObjItem(bpy.types.Operator): 1901 | """Remove selected bake object list""" 1902 | bl_idname = "bakelab.removeobjitem" 1903 | bl_label = "remove bake object list" 1904 | bl_options = {'REGISTER','UNDO'} 1905 | 1906 | @classmethod 1907 | def poll(cls,context): 1908 | return context.scene.BakeLabObjColl 1909 | 1910 | def execute(self,context): 1911 | context.area.tag_redraw() 1912 | context.scene.BakeLabObjColl.remove(context.scene.BakeLabObjListIndex) 1913 | context.scene.BakeLabObjListIndex = max(context.scene.BakeLabObjListIndex - 1,0) 1914 | context.scene.BakeLabObjListIndex = min(context.scene.BakeLabObjListIndex,len(context.scene.BakeLabObjColl)) 1915 | return {'FINISHED'} 1916 | 1917 | class BakeLabSelectObjItem(bpy.types.Operator): 1918 | """Select Objects""" 1919 | bl_idname = "bakelab.selectobjitem" 1920 | bl_label = "Select Objects" 1921 | bl_options = {'REGISTER','UNDO'} 1922 | 1923 | @classmethod 1924 | def poll(cls,context): 1925 | return context.scene.BakeLabObjColl 1926 | 1927 | def execute(self,context): 1928 | context.area.tag_redraw() 1929 | bpy.ops.object.select_all(action='DESELECT') 1930 | scene = context.scene 1931 | item = scene.BakeLabObjColl[scene.BakeLabObjListIndex] 1932 | for obj_col in item.objects: 1933 | if obj_col.object: 1934 | obj_col.object.select = True 1935 | scene.objects.active = item.active 1936 | return {'FINISHED'} 1937 | 1938 | ################################################################ 1939 | 1940 | class BakeLabShowPassPresets(bpy.types.Operator): 1941 | """Show Presets""" 1942 | bl_idname = "bakelab.pass_presets" 1943 | bl_label = "BakeLab Show Pass Presets" 1944 | pass_presets = bpy.props.EnumProperty( 1945 | name = 'Pass Presets', 1946 | items = (('Color|Base Color|Paint Color', 'Color',''), 1947 | ('Metallic', 'Metallic',''), 1948 | ('Specular', 'Specular',''), 1949 | ('Roughness', 'Roughness',''), 1950 | ('Anisotropic', 'Anisotropic',''), 1951 | ('Sheen', 'Sheen',''), 1952 | ('Clearcoat', 'Clearcoat',''), 1953 | ('Transmission', 'Transmission ',''))) 1954 | 1955 | def execute(self,context): 1956 | context.area.tag_redraw() 1957 | scene = context.scene 1958 | if scene.BakeLabMapListIndex>=0 and scene.BakeLabMapColl: 1959 | item = scene.BakeLabMapColl[scene.BakeLabMapListIndex] 1960 | if item: 1961 | item.pass_name = self.pass_presets 1962 | return {'FINISHED'} 1963 | 1964 | ################################################################ 1965 | 1966 | class BakeLabProperties(bpy.types.PropertyGroup): 1967 | use_list = bpy.props.BoolProperty(name = 'Use Object Lists', 1968 | description = 'Use List of Objects Instead of Selected Objects', 1969 | default = False) 1970 | obj_list_settings = bpy.props.BoolProperty(name = '', 1971 | description = 'Show Settings', 1972 | default = False) 1973 | 1974 | s_to_a = bpy.props.BoolProperty(name = 'Selected to Active', 1975 | description = 'Bake From Selected Objects to Active Object', 1976 | default = False) 1977 | s_to_a_settings = bpy.props.BoolProperty(name = '', 1978 | description = 'Show Settings', 1979 | default = False) 1980 | use_cage = bpy.props.BoolProperty(name = 'Use Cage Extrusion', 1981 | description = 'Extrude Object Along Normals Before Baking(Only Cycles)', 1982 | default = False) 1983 | cage_extrusion = bpy.props.FloatProperty(name = '', 1984 | default = 0.0, 1985 | min = 0) 1986 | 1987 | all_in_one = bpy.props.BoolProperty(name = 'All In One', 1988 | description = 'Bake Maps of All Objects Into One Image', 1989 | default = False) 1990 | a_in_1_settings = bpy.props.BoolProperty(name = '', 1991 | description = 'Show Settings', 1992 | default = False) 1993 | general_name = bpy.props.StringProperty(name = 'General Name',default = 'General_Objects') 1994 | ray_limit = bpy.props.FloatProperty(name = 'Ray Limit', 1995 | description = 'Ray Limit', 1996 | default = 0.01, 1997 | min = 0) 1998 | 1999 | unwrap_mode = bpy.props.EnumProperty( 2000 | name = 'Unwrap mode', 2001 | items = (('smart_uv','Smart Project',''), 2002 | ('lightmap','LightMap Project',''))) 2003 | unwrap_settings = bpy.props.BoolProperty(name = '', 2004 | description = 'Show Settings', 2005 | default = False) 2006 | 2007 | smart_uv_angle = bpy.props.FloatProperty(name = 'Angle', 2008 | description = 'Angle Limit', 2009 | default = 66, 2010 | min = 1, 2011 | max = 89) 2012 | smart_uv_margin = bpy.props.FloatProperty(name = 'Margin', 2013 | description = 'Island Margin', 2014 | default = 0.02, 2015 | min = 0, 2016 | max = 1) 2017 | 2018 | lightmap_quality = bpy.props.IntProperty(name = 'Quality', 2019 | description = 'Pack Quality', 2020 | default = 12, 2021 | min = 1, 2022 | max = 48) 2023 | lightmap_margin = bpy.props.FloatProperty(name = 'Margin', 2024 | description = 'Margin', 2025 | default = 0.1, 2026 | min = 0, 2027 | max = 1) 2028 | newuv = bpy.props.BoolProperty(name = 'New UV layer',default = True) 2029 | deluvs = bpy.props.BoolProperty(name = 'Remove Old UVs',default = False) 2030 | compute_device = bpy.props.EnumProperty( 2031 | name = 'Device', 2032 | description = 'Compute Device', 2033 | items = (('GPU','GPU (If Supported)',''), 2034 | ('CPU','CPU',''))) 2035 | linked_datas = bpy.props.EnumProperty( 2036 | name = 'Linked Datas', 2037 | description = 'What to do with multi user data objects', 2038 | items = (('MAKE_SINGLE_USER','Make Single User',''), 2039 | ('EXCLUDE','Exclude Copies',''))) 2040 | aa_samples = bpy.props.IntProperty(name = 'Anti-Aliasing', 2041 | default = 1, 2042 | min = 1, 2043 | soft_max = 8, 2044 | max = 64) 2045 | bake_margin = bpy.props.IntProperty(name = 'Bake Margin', 2046 | description = 'Extends the baked result as a post process filter', 2047 | default = 16, 2048 | min = 0, 2049 | max = 64) 2050 | gen_mat = bpy.props.BoolProperty(name = 'Generate Materials', 2051 | description = 'Generate New Materials Based On Baked Images', 2052 | default = True) 2053 | append_mat = bpy.props.BoolProperty(name = 'Append Materials', 2054 | description = 'Append Generated Materials to Objects', 2055 | default = True) 2056 | save_or_pack = bpy.props.EnumProperty( 2057 | items = (('SAVE','Save Images',''), 2058 | ('PACK','Pack Images','')), 2059 | default = 'SAVE') 2060 | out_path = bpy.props.StringProperty( 2061 | default="C:\\", 2062 | name="Output", 2063 | subtype="FILE_PATH" 2064 | ) 2065 | 2066 | class BakeLabObjectListCollection(bpy.types.PropertyGroup): 2067 | object = bpy.props.PointerProperty(type = bpy.types.Object) 2068 | 2069 | class BakeLabObjectCollection(bpy.types.PropertyGroup): 2070 | enabled = bpy.props.BoolProperty(name = '',default = True) 2071 | name = bpy.props.StringProperty(name = 'List Name',default = 'Group') 2072 | objects = bpy.props.CollectionProperty(type = BakeLabObjectListCollection) 2073 | active = bpy.props.PointerProperty(type = bpy.types.Object) 2074 | image_scale = bpy.props.FloatProperty(name = 'Image Scale', 2075 | description = 'Scale of Image (Image Size * Scale)', 2076 | default = 1, 2077 | min = 0, 2078 | soft_max = 16) 2079 | override_size = bpy.props.BoolProperty(name = 'Override Image Size',default = False) 2080 | width = bpy.props.IntProperty(name = 'Width',default = 1024, 2081 | min = 1, soft_max = 16384) 2082 | height = bpy.props.IntProperty(name = 'Height',default = 1024, 2083 | min = 1, soft_max = 16384) 2084 | sample_scale = bpy.props.FloatProperty(name = 'Sample Scale', 2085 | description = 'Scale of Samples (Amount of Samples * Scale)', 2086 | default = 1, 2087 | min = 0, 2088 | soft_max = 64) 2089 | ray_scale = bpy.props.FloatProperty(name = '', 2090 | default = 1.0, 2091 | min = 0) 2092 | 2093 | class BakeLabMapCollection(bpy.types.PropertyGroup): 2094 | enabled = bpy.props.BoolProperty(name = '',default = True) 2095 | engine = bpy.props.EnumProperty( 2096 | name = 'Engine', 2097 | items = (('BI', 'Blender Internal',''), 2098 | ('CYCLES','Cycles',''))) 2099 | type = bpy.props.EnumProperty( 2100 | name = 'Type', 2101 | items = (('Full', 'Full',''), 2102 | ('Texture', 'Texture',''), 2103 | ('Normal', 'Normal',''), 2104 | ('Ambient', 'Ambient',''), 2105 | ('Shadow', 'Shadow',''), 2106 | ('Glossy', 'Glossy',''), 2107 | ('Emission', 'Emission',''), 2108 | ('Alpha', 'Alpha/Transmission',''), 2109 | ('Displacement','Displacement (BI Only)',''), 2110 | ('Derivative', 'Derivative (BI Only)',''), 2111 | ('Vertex Col', 'Vertex Colors (BI Only)',''), 2112 | ('UV', 'UV (Cycles Only)',''), 2113 | ('Diffuse', 'Diffuse (Cycles Only)',''), 2114 | ('Environment', 'Environment (Cycles Only)',''), 2115 | ('Subsurface', 'Subsurface (Cycles Only)',''), 2116 | ('Passes', 'Custom Passes (Cycles Only)',''))) 2117 | pass_name = bpy.props.StringProperty(name = 'Pass Name',default = 'Color|Base Color|Paint Color') 2118 | pass_multiplier = bpy.props.FloatProperty(name = 'Multiplier', 2119 | description = '(Pass Value * Multiplier) + Addend', 2120 | min = 0, 2121 | default = 1) 2122 | pass_addend = bpy.props.FloatProperty(name = 'Addend', 2123 | description = '(Pass Value * Multiplier) + Addend', 2124 | default = 0) 2125 | img_name = bpy.props.StringProperty(name = 'Name',default = '*_d') 2126 | width = bpy.props.IntProperty(name = 'Width',default = 1024, 2127 | min = 1, soft_max = 16384) 2128 | height = bpy.props.IntProperty(name = 'Height',default = 1024, 2129 | min = 1, soft_max = 16384) 2130 | 2131 | format = bpy.props.EnumProperty( 2132 | name = '', 2133 | items = (('PNG', 'png',''), 2134 | ('JPEG','jpg',''), 2135 | ('TARGA', 'tar',''), 2136 | ('TIFF','tiff',''), 2137 | ('BMP', 'bmp',''))) 2138 | channels3 = bpy.props.EnumProperty( 2139 | name = '', 2140 | items = (('BW','BW',''), 2141 | ('RGB','RGB',''), 2142 | ('RGBA','RGBA','')), 2143 | default = 'RGB') 2144 | channels2 = bpy.props.EnumProperty( 2145 | name = '', 2146 | items = (('BW','BW',''), 2147 | ('RGB','RGB','')), 2148 | default = 'RGB') 2149 | c_depth = bpy.props.EnumProperty( 2150 | name = 'Depth', 2151 | description = 'Color Depth', 2152 | items = (('8','8',''), 2153 | ('16','16','')), 2154 | default = '8') 2155 | compression = bpy.props.IntProperty(name = 'Compression',default = 15, 2156 | description = 'Compression', 2157 | min = 0, max = 100) 2158 | quality = bpy.props.IntProperty(name = 'Quality',default = 90, 2159 | description = 'Quality', 2160 | min = 0, max = 100) 2161 | tiff_codec = bpy.props.EnumProperty( 2162 | name = 'Compression', 2163 | items = (('NONE','None',''), 2164 | ('DEFLATE','Deflate',''), 2165 | ('LZW','LZW',''), 2166 | ('PACKBITS','Pack Bits','')), 2167 | default = 'DEFLATE') 2168 | 2169 | samples = bpy.props.IntProperty(name = 'Samples',default = 6, 2170 | description = 'Amount of Samples (If Supported)', 2171 | min = 1, soft_max = 128) 2172 | 2173 | normalize = bpy.props.BoolProperty(name = 'Normalize',default = False) 2174 | normal_space = bpy.props.EnumProperty( 2175 | name = 'Normal Space', 2176 | items = (('TANGENT','Tangent Space',''), 2177 | ('OBJECT', 'Object Space',''))) 2178 | tricky = bpy.props.BoolProperty( 2179 | name = "Include Material's Normals", 2180 | description = 'Bake Also Bump Nodes Plugged Into BSDFs', 2181 | default = True) 2182 | gloss_type = bpy.props.EnumProperty( 2183 | items = (('SPECULAR','Specular','','',0), 2184 | ('MIRROR','Mirror','','',1))) 2185 | gloss_data = bpy.props.EnumProperty( 2186 | items = (('INTENSITY','Intensity','','',0), 2187 | ('COLOR','Color','','',1))) 2188 | 2189 | cycles_direct = bpy.props.BoolProperty(name = 'Direct', default = True) 2190 | cycles_indirect = bpy.props.BoolProperty(name = 'Indirect', default = True) 2191 | cycles_color = bpy.props.BoolProperty(name = 'Color', default = True) 2192 | cycles_diffuse = bpy.props.BoolProperty(name = 'Diffuse', default = True) 2193 | cycles_glossy = bpy.props.BoolProperty(name = 'Glossy', default = True) 2194 | cycles_transmission = bpy.props.BoolProperty(name = 'Transmission', default = True) 2195 | cycles_subsurface = bpy.props.BoolProperty(name = 'Subsurface', default = True) 2196 | cycles_ambient_occlusion = bpy.props.BoolProperty(name = 'AO', default = True) 2197 | cycles_emit = bpy.props.BoolProperty(name = 'Emit', default = True) 2198 | 2199 | class BakeLabMapListUI(bpy.types.UIList): 2200 | def draw_item(self,context,layout,data,item,icon,active_data,active_propname,index): 2201 | if self.layout_type in {'DEFAULT', 'COMPACT'}: 2202 | if item.type == 'Passes': 2203 | layout.label(item.pass_name,icon = 'NONE') 2204 | else: 2205 | layout.label(item.type,icon = 'NONE') 2206 | elif self.layout_type in {'GRID'}: 2207 | layout.alignment = 'CENTER' 2208 | layout.label("",icon = 'TEXTURE') 2209 | layout.prop(item,'enabled') 2210 | 2211 | class BakeLabObjListUI(bpy.types.UIList): 2212 | def draw_item(self,context,layout,data,item,icon,active_data,active_propname,index): 2213 | if self.layout_type in {'DEFAULT', 'COMPACT'}: 2214 | layout.label(item.name,icon = 'OUTLINER_OB_GROUP_INSTANCE') 2215 | elif self.layout_type in {'GRID'}: 2216 | layout.alignment = 'CENTER' 2217 | layout.label("",icon = 'OUTLINER_OB_GROUP_INSTANCE') 2218 | layout.prop(item,'enabled') 2219 | 2220 | class BakeLabUI(bpy.types.Panel): 2221 | bl_label = 'BakeLab Tools' 2222 | bl_idname = 'bakelab.ui' 2223 | bl_space_type = 'VIEW_3D' 2224 | bl_region_type = 'TOOLS' 2225 | bl_context = "objectmode" 2226 | bl_category = "BakeLab" 2227 | def draw(self,context): 2228 | layout = self.layout 2229 | scene = context.scene 2230 | 2231 | col = layout.column() 2232 | col.scale_y = 1.5 2233 | col.operator('bakelab.bake','Bake',icon = 'RENDER_STILL') 2234 | layout.prop(scene.BakeLabProps,'use_list') 2235 | if scene.BakeLabProps.use_list: 2236 | col = layout.column(align = True) 2237 | row = col.split(align=True) 2238 | row.operator("bakelab.newobjitem", icon='ZOOMIN', text="") 2239 | row.operator("bakelab.removeobjitem", icon='ZOOMOUT', text="") 2240 | row.operator("bakelab.selectobjitem", icon='RESTRICT_SELECT_OFF', text="") 2241 | row.prop(scene.BakeLabProps,'obj_list_settings',icon = 'SCRIPTWIN',toggle = True) 2242 | col.template_list("BakeLabObjListUI", "", scene, 2243 | "BakeLabObjColl", scene, "BakeLabObjListIndex", rows=2, maxrows=5) 2244 | if scene.BakeLabProps.obj_list_settings: 2245 | if scene.BakeLabObjListIndex>=0 and scene.BakeLabObjColl: 2246 | item = scene.BakeLabObjColl[scene.BakeLabObjListIndex] 2247 | box = col.box() 2248 | box.prop(item,'name') 2249 | box.prop(item,'override_size') 2250 | if item.override_size: 2251 | subcol = box.column(align=True) 2252 | subcol.prop(item,'width') 2253 | subcol.prop(item,'height') 2254 | else: 2255 | box.prop(item,'image_scale') 2256 | box.prop(item,'sample_scale') 2257 | if scene.BakeLabProps.s_to_a and scene.BakeLabProps.use_cage: 2258 | box.prop(item,'ray_scale',text = 'Cage Extrusion Scale') 2259 | else: 2260 | box.prop(item,'ray_scale',text = 'Ray Distance Scale') 2261 | col.separator() 2262 | 2263 | row = layout.row(align = True) 2264 | row.prop(scene.BakeLabProps,'s_to_a',toggle = True) 2265 | row.prop(scene.BakeLabProps,'s_to_a_settings',icon = 'SCRIPTWIN',toggle = True) 2266 | if scene.BakeLabProps.s_to_a_settings: 2267 | s2a_col = layout.column() 2268 | s2a_col.prop(scene.BakeLabProps,'use_cage') 2269 | if scene.BakeLabProps.use_cage: 2270 | s2a_col.prop(scene.BakeLabProps,'cage_extrusion',text = 'Cage Extrusion') 2271 | else: 2272 | s2a_col.prop(scene.BakeLabProps,'cage_extrusion',text = 'Ray Distance') 2273 | s2a_col.enabled = scene.BakeLabProps.s_to_a 2274 | 2275 | if not scene.BakeLabProps.s_to_a: 2276 | row = layout.row(align = True) 2277 | row.prop(scene.BakeLabProps,'all_in_one',toggle = True) 2278 | if not scene.BakeLabProps.use_list: 2279 | row.prop(scene.BakeLabProps,'a_in_1_settings',icon = 'SCRIPTWIN',toggle = True) 2280 | if scene.BakeLabProps.a_in_1_settings: 2281 | a_in_1_col = layout.column() 2282 | a_in_1_col.prop(scene.BakeLabProps,'general_name') 2283 | a_in_1_col.prop(scene.BakeLabProps,'ray_limit') 2284 | a_in_1_col.enabled = scene.BakeLabProps.all_in_one 2285 | 2286 | row = layout.row(align = True) 2287 | row.prop(scene.BakeLabProps,'unwrap_mode') 2288 | row.prop(scene.BakeLabProps,'unwrap_settings',icon = 'SCRIPTWIN',toggle = True) 2289 | 2290 | if scene.BakeLabProps.unwrap_settings: 2291 | row = layout.row(align = True) 2292 | if scene.BakeLabProps.unwrap_mode == 'smart_uv': 2293 | row.prop(scene.BakeLabProps,'smart_uv_angle') 2294 | row.prop(scene.BakeLabProps,'smart_uv_margin') 2295 | elif scene.BakeLabProps.unwrap_mode == 'lightmap': 2296 | row.prop(scene.BakeLabProps,'lightmap_quality') 2297 | row.prop(scene.BakeLabProps,'lightmap_margin') 2298 | row = layout.row() 2299 | row.prop(scene.BakeLabProps,'newuv') 2300 | row.prop(scene.BakeLabProps,'deluvs') 2301 | 2302 | layout.prop(scene.BakeLabProps,'compute_device') 2303 | layout.prop(scene.BakeLabProps,'linked_datas') 2304 | 2305 | layout.prop(scene.BakeLabProps,'aa_samples') 2306 | layout.prop(scene.BakeLabProps,'bake_margin') 2307 | 2308 | row = layout.row() 2309 | row.prop(scene.BakeLabProps,'gen_mat') 2310 | col = row.column() 2311 | col.prop(scene.BakeLabProps,'append_mat') 2312 | col.enabled = scene.BakeLabProps.gen_mat 2313 | row = layout.row() 2314 | row.prop(scene.BakeLabProps,'save_or_pack', expand = True) 2315 | if scene.BakeLabProps.save_or_pack == 'SAVE': 2316 | layout.prop(scene.BakeLabProps,'out_path') 2317 | 2318 | layout.separator() 2319 | 2320 | box = layout.box() 2321 | col = box.column(align = True) 2322 | row = col.split(align=True) 2323 | row.operator("bakelab.newmapitem", icon='ZOOMIN', text="") 2324 | row.operator("bakelab.removemapitem", icon='ZOOMOUT', text="") 2325 | col.template_list("BakeLabMapListUI", "", scene, 2326 | "BakeLabMapColl", scene, "BakeLabMapListIndex", rows=2, maxrows=5) 2327 | 2328 | ################################################################### 2329 | 2330 | if scene.BakeLabMapListIndex>=0 and scene.BakeLabMapColl: 2331 | item = scene.BakeLabMapColl[scene.BakeLabMapListIndex] 2332 | 2333 | col = box.column() 2334 | col.enabled = item.enabled 2335 | 2336 | col.prop(item,'type') 2337 | col.prop(item,'img_name') 2338 | subcol = col.column(align=True) 2339 | subcol.prop(item,'width') 2340 | subcol.prop(item,'height') 2341 | 2342 | if scene.BakeLabProps.save_or_pack == 'SAVE': 2343 | row = col.row(align = True) 2344 | row.prop(item,'format') 2345 | if item.format in {'PNG','TARGA','TIFF'}: 2346 | row.prop(item,'channels3') 2347 | elif item.format == 'JPEG': 2348 | row.prop(item,'channels2') 2349 | 2350 | row = col.row() 2351 | if item.format == 'PNG': 2352 | row.prop(item,'compression') 2353 | if item.format == 'JPEG': 2354 | row.prop(item,'quality') 2355 | if item.format == 'TIFF': 2356 | row.prop(item,'tiff_codec') 2357 | if item.format in {'PNG','TIFF'}: 2358 | row.prop(item,'c_depth') 2359 | 2360 | col.separator() 2361 | 2362 | subcol = col.column() 2363 | if item.type in {'Displacement','Derivative','Vertex Col'}: 2364 | item.engine = 'BI' 2365 | subcol.enabled = False 2366 | elif item.type in {'UV','Diffuse','Environment','Subsurface','Passes'}: 2367 | item.engine = 'CYCLES' 2368 | subcol.enabled = False 2369 | 2370 | subcol.prop(item,'engine') 2371 | col.prop(item,'samples') 2372 | 2373 | if item.engine == 'BI': 2374 | if item.type in {'Ambient', 'Displacement'}: 2375 | box.prop(item,'normalize') 2376 | if item.type in {'Glossy'}: 2377 | row = box.row() 2378 | row.prop(item,'gloss_type',expand = True) 2379 | row = box.row() 2380 | row.prop(item,'gloss_data',expand = True) 2381 | if item.engine == 'CYCLES': 2382 | if item.type in {'Full','Diffuse','Glossy','Alpha','Subsurface'}: 2383 | split = box.split(align = True) 2384 | split.prop(item,'cycles_direct',toggle = True) 2385 | split.prop(item,'cycles_indirect',toggle = True) 2386 | if item.type != 'Full': 2387 | split.prop(item,'cycles_color',toggle = True) 2388 | else: 2389 | row = box.row() 2390 | col = row.column() 2391 | col.prop(item,'cycles_diffuse') 2392 | col.prop(item,'cycles_glossy') 2393 | col.prop(item,'cycles_transmission') 2394 | col = row.column() 2395 | col.prop(item,'cycles_subsurface') 2396 | col.prop(item,'cycles_ambient_occlusion') 2397 | col.prop(item,'cycles_emit') 2398 | if item.type in {'Normal'}: 2399 | box.prop(item,'normal_space',expand = True) 2400 | if item.engine == 'CYCLES': 2401 | box.prop(item,'tricky') 2402 | if item.type in {'Passes'}: 2403 | box.separator() 2404 | row = box.row(align = True) 2405 | row.prop(item,'pass_name') 2406 | row.operator_menu_enum('bakelab.pass_presets','pass_presets',icon = 'COLLAPSEMENU',text = '') 2407 | col = box.column(align = True) 2408 | col.prop(item,'pass_multiplier') 2409 | col.prop(item,'pass_addend') 2410 | 2411 | def register(): 2412 | bpy.utils.register_module(__name__) 2413 | bpy.types.Scene.BakeLabProps = bpy.props.PointerProperty(type = BakeLabProperties) 2414 | bpy.types.Scene.BakeLabObjColl = bpy.props.CollectionProperty(type = BakeLabObjectCollection) 2415 | bpy.types.Scene.BakeLabMapColl = bpy.props.CollectionProperty(type = BakeLabMapCollection) 2416 | bpy.types.Scene.BakeLabMapListIndex = bpy.props.IntProperty(name = 'BakeLab Map List Index') 2417 | bpy.types.Scene.BakeLabObjListIndex = bpy.props.IntProperty(name = 'BakeLab Object List Index') 2418 | 2419 | def unregister(): 2420 | bpy.utils.unregister_module(__name__) 2421 | del bpy.types.Scene.BakeLabProps 2422 | del bpy.types.Scene.BakeLabObjColl 2423 | del bpy.types.Scene.BakeLabMapColl 2424 | del bpy.types.Scene.BakeLabMapListIndex 2425 | del bpy.types.Scene.BakeLabObjListIndex 2426 | 2427 | if __name__ == "__main__": 2428 | register() --------------------------------------------------------------------------------