├── .gitignore ├── .vscode ├── launch.json └── settings.json ├── Cargo.toml ├── LICENSE ├── README.md ├── examples ├── README.md ├── dev │ ├── .gitignore │ ├── Cargo.toml │ ├── README.md │ ├── lib │ │ ├── Cargo.toml │ │ └── src │ │ │ └── lib.rs │ └── src │ │ └── main.rs ├── main │ ├── README.md │ ├── circle │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ ├── evolutions │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ └── main.rs │ ├── neo_rug │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ └── main.rs │ ├── orbit │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ └── main.rs │ ├── platonic_life │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ └── main.rs │ ├── run_all.sh │ ├── sphere │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ ├── squares │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ │ └── main.rs │ ├── text │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ ├── tilings │ │ ├── Cargo.toml │ │ └── src │ │ │ └── main.rs │ └── triangles │ │ ├── Cargo.toml │ │ └── src │ │ └── main.rs └── tests │ ├── Cargo.toml │ ├── anim │ ├── Cargo.toml │ └── src │ │ └── lib.rs │ └── src │ └── main.rs ├── vera-core ├── Cargo.toml ├── README.md └── src │ ├── buffers.rs │ ├── fonts │ ├── README.md │ ├── cmunti_msdf_100_005.png │ ├── cmunti_msdf_100_005_rgba.png │ ├── cmunti_mtsdf_128_16.png │ └── cmunti_sdf_128_16.png │ ├── lib.rs │ ├── matrix.rs │ └── transformer.rs └── vera ├── Cargo.toml ├── README.md └── src ├── extensions ├── README.md ├── mod.rs ├── shapes │ └── mod.rs └── text │ ├── font.rs │ ├── fonts │ ├── _cmunti.ttf │ ├── cmunti_msdf_100_005.json │ ├── cmunti_mtsdf_128_16.json │ └── cmunti_sdf_128_16.json │ └── mod.rs ├── lib.rs ├── model.rs ├── projection.rs ├── transform.rs ├── vertex.rs └── view.rs /.gitignore: -------------------------------------------------------------------------------- 1 | # Generated by Cargo 2 | # will have compiled files and executables 3 | debug/ 4 | target/ 5 | 6 | # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries 7 | # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html 8 | Cargo.lock 9 | 10 | # These are backup files generated by rustfmt 11 | **/*.rs.bk 12 | 13 | # MSVC Windows builds of rustc generate these, which store debugging information 14 | *.pdb 15 | 16 | # Random 17 | mre 18 | todo.md -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "0.2.0", 3 | "configurations": [ 4 | // Minimal Reproducible example (local) 5 | { 6 | "type": "cppvsdbg", 7 | "request": "launch", 8 | "name": "Debug mre", 9 | "program": "${workspaceFolder}/target/debug/mre.exe", 10 | "args": [], 11 | "cwd": "${workspaceFolder}" 12 | }, 13 | { 14 | "type": "cppvsdbg", 15 | "request": "launch", 16 | "name": "Release mre", 17 | "program": "${workspaceFolder}/target/release/mre.exe", 18 | "args": [], 19 | "cwd": "${workspaceFolder}" 20 | }, 21 | // Another example 22 | { 23 | "type": "cppvsdbg", 24 | "request": "launch", 25 | "name": "Debug neo_rug", 26 | "program": "${workspaceFolder}/target/debug/neo_rug.exe", 27 | "args": [], 28 | "cwd": "${workspaceFolder}" 29 | }, 30 | { 31 | "type": "cppvsdbg", 32 | "request": "launch", 33 | "name": "Release neo_rug", 34 | "program": "${workspaceFolder}/target/release/neo_rug.exe", 35 | "args": [], 36 | "cwd": "${workspaceFolder}" 37 | } 38 | ] 39 | } -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "rust-analyzer.linkedProjects": [ 3 | "./examples/dev/lib/Cargo.toml", 4 | "./examples/dev/Cargo.toml", 5 | "./vera/Cargo.toml", 6 | ], 7 | "workbench.colorTheme": "Palenight (Mild Contrast)" 8 | } 9 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "vera", 4 | "vera-core", 5 | "examples/main/*", # "mre", 6 | ] 7 | resolver = "2" 8 | 9 | [workspace.dependencies.vera-core] 10 | version = "0.3.0" 11 | path = "vera-core" 12 | 13 | [workspace.dependencies.vera] 14 | version = "0.3.0" 15 | path = "vera" 16 | 17 | 18 | [profile.dev] 19 | opt-level = 1 20 | 21 | [profile.release] 22 | opt-level = 3 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Vera 2 | Vulkan Engine in Rust for Animation. 3 | 4 | Development video series: [YouTube](https://www.youtube.com/playlist?list=PLFBSAg3dVe4z5HxaZmOH0gaojQH4tLEgF) 5 | 6 | This repository is split into: 7 | - ( `docs`, text of the user documentation hosted at [https://coddeus.github.io/vera](https://coddeus.github.io/vera), ) 8 | - `examples`, 9 | - 2 crates: 10 | - `vera-core` for the (heavier) core engine ([crates.io](https://crates.io/crates/vera-core)), 11 | - `vera` for the code interface (should be the only one imported in the hot-reloaded library) ([crates.io](https://crates.io/crates/vera)), 12 | 13 | ## Features (section to be removed for the docs) 14 | - Draw anything out of triangles, by creating models from vertices, or by merging together several models you have already created. 15 | - Send metadata for the background color, start time, and end time of the animation. 16 | --- 17 | - Choose the default color and position of vertices 18 | - Modify the color and position of each vertex, independently. 19 | - Modify the color and position of each model. 20 | - Modify the camera view to look wherever you want. 21 | - Modify the projection to any custom perspective. 22 | --- 23 | - Choose the start time and end time of each modification. 24 | - Every modification is done at runtime, but you can make them start and end both at 0.0 to apply them directly. 25 | - Here are the currently available transformations: 26 | 27 | | Type of transformations | Available transformations | 28 | |-------------------------|-------------------------------------------------------------------------------------------| 29 | | Vertex / Model |
  • Scale
  • RotateX
  • RotateY
  • RotateZ
  • Translate
| 30 | | View (= Camera) |
  • Lookat
| 31 | | Projection |
  • Perspective
| 32 | --- 33 | - Hot-reloaded workflow (see ./examples/dev). 34 | --- 35 | - Examples to get what's possible to do, and inspire you to do something great. 36 | 37 | #### Coming 38 | - Much :) 39 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | - `dev` contains an example hot-reloaded development workflow, which reloads every time the animation ends. This is also where I try new features and create random animation. 3 | - `main` contains (hopefully) working examples, run once. 4 | - `tests` contains other examples made to test the behaviour of the engine. -------------------------------------------------------------------------------- /examples/dev/.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | -------------------------------------------------------------------------------- /examples/dev/Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | members = ["lib"] 4 | 5 | [package] 6 | name = "vera-example-dev" 7 | version = "0.1.0" 8 | edition = "2021" 9 | 10 | [dependencies] 11 | lib = { path = "./lib" } 12 | hot-lib-reloader = "^0.6" 13 | vera-core = { path = "../../vera-core" } 14 | vera = { path = "../../vera" } -------------------------------------------------------------------------------- /examples/dev/README.md: -------------------------------------------------------------------------------- 1 | # Dev 2 | Vera with hot-reload for development. 3 | 4 | ## Usage 5 | In the folder of this README: 6 | ```shell 7 | cargo watch -w lib -x 'build -p lib' 8 | # Another terminal 9 | cargo run 10 | ``` 11 | 12 | Then, modifying the get() function in `lib/src/lib.rs` will modify the render when the animation restarts. 13 | src/main.rs is an intermediate. It sends the `Input` returned from the hot lib to vera. -------------------------------------------------------------------------------- /examples/dev/lib/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "lib" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | crate-type = ["rlib", "dylib"] 8 | 9 | [dependencies] 10 | vera = { path = "../../../vera" } 11 | fastrand = "2.0.1" 12 | itertools = "0.12.0" -------------------------------------------------------------------------------- /examples/dev/lib/src/lib.rs: -------------------------------------------------------------------------------- 1 | use vera::*; 2 | 3 | // Tilings / Tessellations. 4 | 5 | #[no_mangle] 6 | fn get() -> Input { 7 | unsafe { 8 | D_TRANSFORMATION_START_TIME = -1.; 9 | D_TRANSFORMATION_END_TIME = -1.; 10 | D_COLORIZATION_START_TIME = -1.; 11 | D_COLORIZATION_END_TIME = -1.; 12 | } 13 | Input { 14 | meta: MetaInput { 15 | bg: [0.1, 0.1, 0.1, 0.1], 16 | start: 0.0, 17 | end: 10.0, 18 | }, 19 | m: vec![ 20 | Model::from_vertices(vec![ 21 | Vertex::new().pos(0., 1., 0.).b(1.), 22 | Vertex::new().pos(3.0f32.sqrt()/2., -0.5, 0.).b(1.), 23 | Vertex::new().pos(-3.0f32.sqrt()/2., -0.5, 0.).b(1.), 24 | ]) 25 | ], 26 | v: View::new().transform(Transformation::Lookat(0., 0., -3., 0., 0., 0., 0., -1., 0.)), 27 | p: Projection::new().transform(Transformation::Perspective(-0.1, 0.1, -0.1, 0.1, 0.2, 100.)), 28 | } 29 | } -------------------------------------------------------------------------------- /examples/dev/src/main.rs: -------------------------------------------------------------------------------- 1 | use vera_core::*; 2 | 3 | #[hot_lib_reloader::hot_module(dylib = "lib")] 4 | mod hot_lib { 5 | use vera::Input; 6 | // Path form the project root 7 | 8 | #[hot_function] 9 | pub fn get() -> Input {} 10 | } 11 | 12 | fn main() { 13 | let mut v = Vera::init(hot_lib::get()); 14 | 15 | // v.show(); 16 | while v.show() { 17 | v.reset(hot_lib::get()) 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /examples/main/README.md: -------------------------------------------------------------------------------- 1 | # Examples 2 | Run `./run_all.sh` from this folder to run them all in a row. -------------------------------------------------------------------------------- /examples/main/circle/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "circle" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | vera-core = { path = "../../../vera-core" } 8 | vera = { path = "../../../vera" } 9 | -------------------------------------------------------------------------------- /examples/main/circle/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | 3 | use vera::*; 4 | use vera_core::*; 5 | 6 | fn main() { 7 | let mut v = Vera::init(get()); 8 | unsafe { 9 | D_VERTEX_ALPHA = 1.0; 10 | } 11 | 12 | v.show(); 13 | } 14 | 15 | fn get() -> Input { 16 | let points: u32 = 100; 17 | 18 | 19 | Input { 20 | meta: MetaInput { 21 | bg: [0.0, 0.0, 0.0, 1.0], 22 | start: -2.0, 23 | end: 7.0, 24 | }, 25 | m: { 26 | let text = text::Text::new("Circle".to_owned(), 0.1, 0.2, 0.0).model() 27 | .rgb(1.0, 1.0, 1.0) 28 | .alpha(1.0) 29 | .transform(Transformation::Scale(1.0, -1.0, 1.0)).start_t(-2.0).end_t(-2.0) 30 | .transform(Transformation::Translate(-0.2, 0.0, 0.0)).start_t(-2.0).end_t(-2.0) 31 | .recolor(Colorization::ToColor(1.0, 1.0, 1.0, 0.0)) 32 | .start_c(-1.0) 33 | .end_c(0.5); 34 | let mut points: Vec = (0..points) 35 | .map(|n| { 36 | let a = n as f32 / points as f32 * 2.0; 37 | point(0.9, 0.0, 0.01, a) 38 | .transform(Transformation::RotateZ(a * PI)) 39 | .evolution_t(Evolution::FastIn) 40 | .start_t(2.0-a) 41 | .end_t(4.0) 42 | } 43 | ).collect(); 44 | points.push(text); 45 | points 46 | }, 47 | v: View::new(), 48 | p: Projection::new(), 49 | } 50 | } 51 | 52 | fn point(x: f32, y: f32, rad: f32, spawn: f32) -> Model { 53 | circle(x, y, rad, spawn) 54 | .rgb(1.0, 1.0, 1.0) 55 | .alpha(0.0) 56 | } 57 | 58 | fn circle(x: f32, y: f32, rad: f32, spawn: f32) -> Model { 59 | Model::from_models( 60 | (0..100).map(|n| Model::from_vertices(vec![ 61 | Vertex::new().pos(x, y, 0.0), 62 | Vertex::new().pos(x + ( n as f32 / 50.0 * PI).cos() * rad, y + ( n as f32 / 50.0 * PI).sin() * rad, 0.0), 63 | Vertex::new().pos(x + ((n+1) as f32 / 50.0 * PI).cos() * rad, y + ((n+1) as f32 / 50.0 * PI).sin() * rad, 0.0), 64 | ]) 65 | .recolor(Colorization::ToColor(1.0, 1.0, 1.0, 1.0)) 66 | .start_c(2.0-spawn) 67 | .end_c(4.0-spawn) 68 | .evolution_c(Evolution::Linear)) 69 | .collect() 70 | ) 71 | } -------------------------------------------------------------------------------- /examples/main/evolutions/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "evolutions" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | vera-core = { path = "../../../vera-core" } 10 | vera = { path = "../../../vera" } -------------------------------------------------------------------------------- /examples/main/evolutions/README.md: -------------------------------------------------------------------------------- 1 | # This example 2 | A visualization of the available animation evolutions for Vera. -------------------------------------------------------------------------------- /examples/main/evolutions/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | 3 | use vera::*; 4 | use vera_core::*; 5 | 6 | fn main() { 7 | let mut v = Vera::init(get()); 8 | unsafe { 9 | D_VERTEX_ALPHA = 1.0; 10 | } 11 | 12 | v.show(); 13 | } 14 | 15 | fn get() -> Input { 16 | Input { 17 | meta: Default::default(), 18 | m: vec![ 19 | circle(-0.8, Evolution::FastIn), 20 | circle(-0.4, Evolution::FastInOut), 21 | circle(0.0, Evolution::Linear), 22 | circle(0.4, Evolution::FastMiddle), 23 | circle(0.8, Evolution::FastOut), 24 | ], 25 | v: View::new(), 26 | p: Projection::new(), 27 | } 28 | } 29 | 30 | fn circle(height: f32, evolution: Evolution) -> Model { 31 | Model::from_models( 32 | (0..100).map(|n| Model::from_vertices(vec![ 33 | Vertex::new().pos(0.0, 0.0, 0.0), 34 | Vertex::new().pos(( n as f32 / 50.0 * PI).cos() * 0.15, ( n as f32 / 50.0 * PI).sin() * 0.15, 0.0), 35 | Vertex::new().pos(((n+1) as f32 / 50.0 * PI).cos() * 0.15, ((n+1) as f32 / 50.0 * PI).sin() * 0.15, 0.0), 36 | ])).collect() 37 | ) 38 | .rgb(1.0, 0.0, 0.0) 39 | .transform(Transformation::Translate(-0.75, height, 0.0)).start_t(0.0).end_t(0.0) 40 | .transform(Transformation::Translate(1.5, 0.0, 0.0)).start_t(1.0).end_t(2.0).evolution_t(evolution) 41 | .recolor(Colorization::ToColor(0.0, 0.0, 1.0, 1.0)).start_c(1.0).end_c(2.0).evolution_c(evolution) 42 | } -------------------------------------------------------------------------------- /examples/main/neo_rug/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "neo_rug" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | vera-core = { path = "../../../vera-core" } 10 | vera = { path = "../../../vera" } -------------------------------------------------------------------------------- /examples/main/neo_rug/README.md: -------------------------------------------------------------------------------- 1 | # This example 2 | A static "rug" example. -------------------------------------------------------------------------------- /examples/main/neo_rug/src/main.rs: -------------------------------------------------------------------------------- 1 | //! This example was made before animation was implemented. It calculates vertices directly for a static image. 2 | 3 | use vera::*; 4 | use vera::shapes::*; 5 | use vera_core::*; 6 | 7 | fn main() { 8 | let mut v = Vera::init(get()); 9 | unsafe { 10 | D_VERTEX_ALPHA = 1.0; 11 | } 12 | 13 | v.show(); 14 | } 15 | 16 | fn get() -> Input { 17 | Input { 18 | meta: Default::default(), 19 | m: (0..100) 20 | .into_iter() 21 | .map(|n| { 22 | Model::from_models({ 23 | vec![ 24 | Triangle::from_vertices( 25 | Vertex::new() 26 | .pos((n / 10 - 5) as f32 / 5.0, (n % 10 - 5) as f32 / 5.0, 0.0) 27 | .rgb(0.0, 1.0, 1.0), 28 | Vertex::new() 29 | .pos( 30 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 31 | (n % 10 - 5) as f32 / 5.0, 32 | 0.0, 33 | ) 34 | .rgb(1.0, 0.0, 1.0), 35 | Vertex::new() 36 | .pos( 37 | (n / 10 - 5) as f32 / 5.0, 38 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 39 | 0.0, 40 | ) 41 | .rgb(1.0, 0.0, 1.0), 42 | ).model(), 43 | Triangle::from_vertices( 44 | Vertex::new() 45 | .pos( 46 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 47 | (n % 10 - 5) as f32 / 5.0, 48 | 0.0, 49 | ) 50 | .rgb(1.0, 0.0, 1.0), 51 | Vertex::new() 52 | .pos( 53 | (n / 10 - 5) as f32 / 5.0, 54 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 55 | 0.0, 56 | ) 57 | .rgb(1.0, 0.0, 1.0), 58 | Vertex::new() 59 | .pos( 60 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 61 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 62 | 0.0, 63 | ) 64 | .rgb(0.0, 1.0, 1.0), 65 | ).model(), 66 | Triangle::from_vertices( 67 | Vertex::new() 68 | .pos( 69 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 70 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 71 | 0.0, 72 | ) 73 | .rgb(0.0, 1.0, 1.0), 74 | Vertex::new() 75 | .pos( 76 | ((n / 10 - 5) as f32 + 1.0) / 5.0, 77 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 78 | 0.0, 79 | ) 80 | .rgb(1.0, 0.0, 1.0), 81 | Vertex::new() 82 | .pos( 83 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 84 | ((n % 10 - 5) as f32 + 1.0) / 5.0, 85 | 0.0, 86 | ) 87 | .rgb(1.0, 0.0, 1.0), 88 | ).model(), 89 | Triangle::from_vertices( 90 | Vertex::new() 91 | .pos( 92 | ((n / 10 - 5) as f32 + 1.0) / 5.0, 93 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 94 | 0.0, 95 | ) 96 | .rgb(1.0, 0.0, 1.0), 97 | Vertex::new() 98 | .pos( 99 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 100 | ((n % 10 - 5) as f32 + 1.0) / 5.0, 101 | 0.0, 102 | ) 103 | .rgb(1.0, 0.0, 1.0), 104 | Vertex::new() 105 | .pos( 106 | ((n / 10 - 5) as f32 + 1.0) / 5.0, 107 | ((n % 10 - 5) as f32 + 1.0) / 5.0, 108 | 0.0, 109 | ) 110 | .rgb(0.0, 1.0, 1.0), 111 | ).model(), 112 | Triangle::from_vertices( 113 | Vertex::new() 114 | .pos( 115 | ((n / 10 - 5) as f32 + 1.0) / 5.0, 116 | (n % 10 - 5) as f32 / 5.0, 117 | 0.0, 118 | ) 119 | .rgb(0.0, 1.0, 1.0), 120 | Vertex::new() 121 | .pos( 122 | ((n / 10 - 5) as f32 + 1.0) / 5.0, 123 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 124 | 0.0, 125 | ) 126 | .rgb(1.0, 0.0, 1.0), 127 | Vertex::new() 128 | .pos( 129 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 130 | (n % 10 - 5) as f32 / 5.0, 131 | 0.0, 132 | ) 133 | .rgb(1.0, 0.0, 1.0), 134 | ).model(), 135 | Triangle::from_vertices( 136 | Vertex::new() 137 | .pos( 138 | ((n / 10 - 5) as f32 + 1.0) / 5.0, 139 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 140 | 0.0, 141 | ) 142 | .rgb(1.0, 0.0, 1.0), 143 | Vertex::new() 144 | .pos( 145 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 146 | (n % 10 - 5) as f32 / 5.0, 147 | 0.0, 148 | ) 149 | .rgb(1.0, 0.0, 1.0), 150 | Vertex::new() 151 | .pos( 152 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 153 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 154 | 0.0, 155 | ) 156 | .rgb(0.0, 1.0, 1.0), 157 | ).model(), 158 | Triangle::from_vertices( 159 | Vertex::new() 160 | .pos( 161 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 162 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 163 | 0.0, 164 | ) 165 | .rgb(0.0, 1.0, 1.0), 166 | Vertex::new() 167 | .pos( 168 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 169 | ((n % 10 - 5) as f32 + 1.0) / 5.0, 170 | 0.0, 171 | ) 172 | .rgb(1.0, 0.0, 1.0), 173 | Vertex::new() 174 | .pos( 175 | (n / 10 - 5) as f32 / 5.0, 176 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 177 | 0.0, 178 | ) 179 | .rgb(1.0, 0.0, 1.0), 180 | ).model(), 181 | Triangle::from_vertices( 182 | Vertex::new() 183 | .pos( 184 | ((n / 10 - 5) as f32 + 0.5) / 5.0, 185 | ((n % 10 - 5) as f32 + 1.0) / 5.0, 186 | 0.0, 187 | ) 188 | .rgb(1.0, 0.0, 1.0), 189 | Vertex::new() 190 | .pos( 191 | (n / 10 - 5) as f32 / 5.0, 192 | ((n % 10 - 5) as f32 + 0.5) / 5.0, 193 | 0.0, 194 | ) 195 | .rgb(1.0, 0.0, 1.0), 196 | Vertex::new() 197 | .pos( 198 | (n / 10 - 5) as f32 / 5.0, 199 | ((n % 10 - 5) as f32 + 1.0) / 5.0, 200 | 0.0, 201 | ) 202 | .rgb(0.0, 1.0, 1.0), 203 | ).model(), 204 | ] 205 | }) 206 | }) 207 | .collect(), 208 | v: View::new(), 209 | p: Projection::new(), 210 | } 211 | 212 | // // More triangles 213 | // (0..10000) 214 | // .into_iter() 215 | // .map(|n| Shape::from_merge({ 216 | // vec![ 217 | // Triangle::new( 218 | // Vertex::new().pos((n/100-50) as f32 / 50.0 , (n%100-50) as f32 / 50.0 , 0.0).rgb(0.0, 1.0, 1.0), 219 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , (n%100-50) as f32 / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 220 | // Vertex::new().pos((n/100-50) as f32 / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 221 | // ), 222 | // Triangle::new( 223 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , (n%100-50) as f32 / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 224 | // Vertex::new().pos((n/100-50) as f32 / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 225 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(0.0, 1.0, 1.0), 226 | // ), 227 | // Triangle::new( 228 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(0.0, 1.0, 1.0), 229 | // Vertex::new().pos(((n/100-50) as f32 + 1.0) / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 230 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , ((n%100-50) as f32 + 1.0) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 231 | // ), 232 | // Triangle::new( 233 | // Vertex::new().pos(((n/100-50) as f32 + 1.0) / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 234 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , ((n%100-50) as f32 + 1.0) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 235 | // Vertex::new().pos(((n/100-50) as f32 + 1.0) / 50.0 , ((n%100-50) as f32 + 1.0) / 50.0 , 0.0).rgb(0.0, 1.0, 1.0), 236 | // ), 237 | // Triangle::new( 238 | // Vertex::new().pos(((n/100-50) as f32 + 1.0) / 50.0 , (n%100-50) as f32 / 50.0 , 0.0).rgb(0.0, 1.0, 1.0), 239 | // Vertex::new().pos(((n/100-50) as f32 + 1.0) / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 240 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , (n%100-50) as f32 / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 241 | // ), 242 | // Triangle::new( 243 | // Vertex::new().pos(((n/100-50) as f32 + 1.0) / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 244 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , (n%100-50) as f32 / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 245 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(0.0, 1.0, 1.0), 246 | // ), 247 | // Triangle::new( 248 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(0.0, 1.0, 1.0), 249 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , ((n%100-50) as f32 + 1.0) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 250 | // Vertex::new().pos((n/100-50) as f32 / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 251 | // ), 252 | // Triangle::new( 253 | // Vertex::new().pos(((n/100-50) as f32 + 0.5) / 50.0 , ((n%100-50) as f32 + 1.0) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 254 | // Vertex::new().pos((n/100-50) as f32 / 50.0 , ((n%100-50) as f32 + 0.5) / 50.0 , 0.0).rgb(1.0, 0.0, 1.0), 255 | // Vertex::new().pos((n/100-50) as f32 / 50.0 , ((n%100-50) as f32 + 1.0) / 50.0 , 0.0).rgb(0.0, 1.0, 1.0), 256 | // ), 257 | // ] 258 | // })) 259 | // .collect() 260 | } 261 | -------------------------------------------------------------------------------- /examples/main/orbit/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "orbit" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | vera-core = { path = "../../../vera-core" } 10 | vera = { path = "../../../vera" } 11 | fastrand = "2.0.1" -------------------------------------------------------------------------------- /examples/main/orbit/README.md: -------------------------------------------------------------------------------- 1 | # This example 2 | A camera orbit and a projection smooth change, around 3D shapes. -------------------------------------------------------------------------------- /examples/main/orbit/src/main.rs: -------------------------------------------------------------------------------- 1 | use vera::*; 2 | use vera_core::*; 3 | use fastrand; 4 | 5 | fn main() { 6 | let mut v = Vera::init(get()); 7 | unsafe { 8 | D_VERTEX_ALPHA = 1.0; 9 | } 10 | 11 | v.show(); 12 | } 13 | 14 | fn get() -> Input { 15 | Input { 16 | meta: MetaInput { 17 | bg: [0.0, 0.0, 0.0, 1.0], 18 | start: 0.0, 19 | end: 10.0, 20 | }, 21 | m: (0..64) 22 | .map(|n| 23 | Model::from_models( 24 | vec![ 25 | Model::from_vertices(vec![ 26 | Vertex::new().pos(1.0, 1.0, 1.0), 27 | Vertex::new().pos(-1.0, -1.0, 1.0), 28 | Vertex::new().pos(1.0, -1.0, -1.0), 29 | ]).rgb(0.0, 0.0, (fastrand::f32()+1.0) / 2.0), 30 | Model::from_vertices(vec![ 31 | Vertex::new().pos(1.0, 1.0, 1.0), 32 | Vertex::new().pos(-1.0, 1.0, -1.0), 33 | Vertex::new().pos(1.0, -1.0, -1.0), 34 | ]).rgb((fastrand::f32()+1.0) / 2.0, 0.0, 0.0), 35 | Model::from_vertices(vec![ 36 | Vertex::new().pos(1.0, 1.0, 1.0), 37 | Vertex::new().pos(-1.0, 1.0, -1.0), 38 | Vertex::new().pos(-1.0, -1.0, 1.0), 39 | ]).rgb(0.0, (fastrand::f32()+1.0) / 2.0, 0.0), 40 | Model::from_vertices(vec![ 41 | Vertex::new().pos(-1.0, -1.0, 1.0), 42 | Vertex::new().pos(-1.0, 1.0, -1.0), 43 | Vertex::new().pos(1.0, -1.0, -1.0), 44 | ]).rgb((fastrand::f32()+1.0) / 2.0, 0.0, (fastrand::f32()+1.0) / 2.0).alpha(fastrand::f32() / 2.0), 45 | ] 46 | ) 47 | .transform(Transformation::Scale(0.1, 0.1, 0.1)).start_t(1.0+n as f32/250.0).end_t(1.5+n as f32/250.0).evolution_t(Evolution::FastIn) 48 | .transform(Transformation::Translate(0.8, 1.2, 0.8)).start_t(1.0+n as f32/250.0).end_t(1.5+n as f32/250.0).evolution_t(Evolution::FastIn) 49 | .transform(Transformation::Translate(-0.8, -1.2, -0.8)).start_t(2.0+n as f32/250.0).end_t(2.5+n as f32/250.0).evolution_t(Evolution::FastIn) 50 | .transform(Transformation::Translate(((n/16) as f32 - 1.5) / 2.0, (((n%16)/4) as f32 - 1.5) / 2.0, ((n%4) as f32 - 1.5) / 2.0)).start_t(2.0+n as f32/250.0).end_t(2.5+n as f32/250.0).evolution_t(Evolution::FastIn) 51 | ).collect(), 52 | v: View::new() 53 | .transform(Transformation::Lookat(3.0, 4.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)).start_t(0.0).end_t(0.0).evolution_t(Evolution::Linear) 54 | .transform(Transformation::Lookat(1.5, 2.0, 1.5, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)).start_t(1.0).end_t(2.0).evolution_t(Evolution::FastIn) 55 | .transform(Transformation::Lookat(0.0, 0.0, -3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)).start_t(3.0).end_t(5.0).evolution_t(Evolution::FastMiddle) 56 | .transform(Transformation::Lookat(0.0, 0.0, -21.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)).start_t(6.0).end_t(7.0).evolution_t(Evolution::FastMiddle) 57 | .transform(Transformation::Lookat(0.0, 0.0, -1.1, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)).start_t(7.0).end_t(9.0).evolution_t(Evolution::FastMiddle), 58 | p: Projection::new() 59 | .transform(Transformation::Perspective(-0.1, 0.1, -0.1, 0.1, 0.2, 25.0)).start_t(0.0).end_t(0.0).evolution_t(Evolution::Linear) 60 | .transform(Transformation::Perspective(-0.1, 0.1, -0.1, 0.1, 2.0, 25.0)).start_t(6.0).end_t(7.0).evolution_t(Evolution::FastMiddle) 61 | .transform(Transformation::Perspective(-0.1, 0.1, -0.1, 0.1, 0.02, 25.0)).start_t(7.0).end_t(9.0).evolution_t(Evolution::FastMiddle), 62 | } 63 | } 64 | 65 | 66 | -------------------------------------------------------------------------------- /examples/main/platonic_life/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "platonic_solids" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | vera-core = { path = "../../../vera-core" } 10 | vera = { path = "../../../vera" } 11 | fastrand = "2.0.1" -------------------------------------------------------------------------------- /examples/main/platonic_life/README.md: -------------------------------------------------------------------------------- 1 | # This example 2 | An animation (with synced music [here](https://youtu.be/qrc3N8UQqFs)) of platonic solids, typical usage of the model hierarchy system: create the solids moving polygons, then animate the solid without having to animate every polygon independently. 3 | -------------------------------------------------------------------------------- /examples/main/platonic_life/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | 3 | use fastrand; 4 | 5 | use vera_core::Vera; 6 | use vera::{ 7 | Input, View, Projection, Model, Vertex, Transformation, MetaInput, Evolution, D_TRANSFORMATION_START_TIME, D_TRANSFORMATION_END_TIME, D_TRANSFORMATION_SPEED_EVOLUTION, 8 | }; 9 | 10 | fn main() { 11 | let mut v = Vera::init(get()); 12 | v.show(); 13 | } 14 | 15 | fn get() -> Input { 16 | 17 | // Platonic life animation 18 | 19 | unsafe { 20 | D_TRANSFORMATION_START_TIME = -100.; 21 | D_TRANSFORMATION_END_TIME = -100.; 22 | D_TRANSFORMATION_SPEED_EVOLUTION = Evolution::FastMiddle; 23 | } 24 | 25 | let tetrahedron = Model::from_models(vec![ 26 | polygon(3, [false, false, true]) 27 | .transform(Transformation::RotateZ(PI/2.)) 28 | .transform(Transformation::Translate(0., 1., 0.)) 29 | .transform(Transformation::RotateX(0.3398)), 30 | polygon(3, [false, false, true]) 31 | .transform(Transformation::RotateZ(PI/2.)) 32 | .transform(Transformation::Translate(0., 1., 0.)) 33 | .transform(Transformation::RotateX(0.3398)) 34 | .transform(Transformation::RotateY(PI/1.5)), 35 | polygon(3, [false, false, true]) 36 | .transform(Transformation::RotateZ(PI/2.)) 37 | .transform(Transformation::Translate(0., 1., 0.)) 38 | .transform(Transformation::RotateX(0.3398)) 39 | .transform(Transformation::RotateY(-PI/1.5)), 40 | polygon(3, [false, false, true]) 41 | .transform(Transformation::RotateZ(PI/2.)) 42 | .transform(Transformation::RotateX(PI/2.)) 43 | .transform(Transformation::Translate(0., 2.0f32.sqrt(), 0.)), 44 | ]) 45 | .transform(Transformation::Translate(0., -1., 0.)) 46 | 47 | .transform(Transformation::Scale(0.1, 0.1, 0.1)) 48 | .transform(Transformation::Scale(10., 10., 10.)).start_t(1.).end_t(2.5) 49 | .transform(Transformation::Scale(1.2, 1.2, 1.2)).start_t(71.74).end_t(72.30).evolution_t(Evolution::Linear) 50 | 51 | .transform(Transformation::RotateY(4.*PI)).start_t(2.).end_t(7.) 52 | .transform(Transformation::RotateX(-2.*PI)).start_t(2.).end_t(7.) 53 | .transform(Transformation::RotateY(4.*PI)).start_t(7.).end_t(12.) 54 | .transform(Transformation::RotateX(-2.*PI)).start_t(7.).end_t(12.) 55 | .transform(Transformation::RotateY(4.*PI)).start_t(12.).end_t(17.) 56 | .transform(Transformation::RotateX(-2.*PI)).start_t(12.).end_t(17.) 57 | .transform(Transformation::RotateY(4.*PI)).start_t(17.).end_t(22.) 58 | .transform(Transformation::RotateX(-2.*PI)).start_t(17.).end_t(22.) 59 | .transform(Transformation::RotateY(4.*PI)).start_t(22.).end_t(27.) 60 | .transform(Transformation::RotateX(-2.*PI)).start_t(22.).end_t(27.) 61 | .transform(Transformation::RotateY(4.*PI)).start_t(27.).end_t(32.) 62 | .transform(Transformation::RotateX(-2.*PI)).start_t(27.).end_t(32.) 63 | .transform(Transformation::RotateY(4.*PI)).start_t(32.).end_t(37.) 64 | .transform(Transformation::RotateX(-2.*PI)).start_t(32.).end_t(37.) 65 | .transform(Transformation::RotateY(4.*PI)).start_t(37.).end_t(43.) 66 | .transform(Transformation::RotateX(-2.*PI)).start_t(37.).end_t(43.) 67 | 68 | .transform(Transformation::Translate(0., 3.0, 0.)).start_t(44.).end_t(55.) 69 | .transform(Transformation::RotateX(10.*PI)).start_t(44.).end_t(55.) 70 | .transform(Transformation::Translate(0., -3.0, 0.)).start_t(55.).end_t(58.) 71 | .transform(Transformation::RotateX(-10.*PI)).start_t(55.).end_t(58.) 72 | 73 | .transform(Transformation::Translate(-8., 0., 0.)) 74 | 75 | .rotound(-6., 60.39, 60.71, true) 76 | .rotound(-2., 60.71, 61.03, false) 77 | .rotound(2., 61.03, 61.35, true) 78 | .rotound(6., 61.35, 61.67, false) 79 | 80 | .rotound(6., 64.06, 64.38, false) 81 | .rotound(2., 64.38, 64.80, true) 82 | .rotound(-2., 64.80, 65.12, false) 83 | .rotound(-6., 65.12, 65.44, true) 84 | 85 | .transform(Transformation::Translate(0., -1., 0.)).start_t(67.05).end_t(67.33).evolution_t(Evolution::FastIn) 86 | .transform(Transformation::Translate(0., 1., 0.)).start_t(68.17).end_t(68.45).evolution_t(Evolution::FastIn) 87 | 88 | .transform(Transformation::Translate(0., 1., 0.)).start_t(70.90).end_t(71.18).evolution_t(Evolution::FastIn) 89 | .transform(Transformation::Translate(0., -5., 0.)).start_t(72.02).end_t(72.30).evolution_t(Evolution::FastIn) 90 | .transform(Transformation::Translate(2., 0., 0.)).start_t(72.02).end_t(72.30).evolution_t(Evolution::FastOut) 91 | .transform(Transformation::Translate(0., 2., 0.)).start_t(72.30).end_t(72.58).evolution_t(Evolution::FastOut) 92 | .transform(Transformation::Translate(2., 0., 0.)).start_t(72.30).end_t(72.58).evolution_t(Evolution::FastIn) 93 | .transform(Transformation::Translate(0., 7., 0.)).start_t(72.58).end_t(72.86).evolution_t(Evolution::FastIn) 94 | .transform(Transformation::Translate(2., 0., 0.)).start_t(72.58).end_t(72.86).evolution_t(Evolution::FastOut) 95 | .transform(Transformation::Translate(0., -5., 0.)).start_t(72.86).end_t(73.14).evolution_t(Evolution::FastOut) 96 | .transform(Transformation::Translate(2., 0., 0.)).start_t(72.86).end_t(73.14).evolution_t(Evolution::FastIn) 97 | ; 98 | 99 | let cube = Model::from_models(vec![ 100 | polygon(4, [false, true, true]) 101 | .transform(Transformation::RotateX(PI/2.)) 102 | .transform(Transformation::Translate(0.0, 2.0f32.sqrt()/2., 0.)) 103 | , 104 | polygon(4, [false, true, true]) 105 | .transform(Transformation::RotateX(PI/2.)) 106 | .transform(Transformation::Translate(0.0, -2.0f32.sqrt()/2., 0.)) 107 | , 108 | polygon(4, [false, true, true]) 109 | .transform(Transformation::RotateZ(PI/4.)) 110 | .transform(Transformation::RotateY(PI/4.)) 111 | .transform(Transformation::Translate(0.5, 0., 0.5)) 112 | , 113 | polygon(4, [false, true, true]) 114 | .transform(Transformation::RotateZ(PI/4.)) 115 | .transform(Transformation::RotateY(PI/4.)) 116 | .transform(Transformation::Translate(-0.5, 0., -0.5)) 117 | , 118 | polygon(4, [false, true, true]) 119 | .transform(Transformation::RotateZ(PI/4.)) 120 | .transform(Transformation::RotateY(-PI/4.)) 121 | .transform(Transformation::Translate(0.5, 0., -0.5)) 122 | , 123 | polygon(4, [false, true, true]) 124 | .transform(Transformation::RotateZ(PI/4.)) 125 | .transform(Transformation::RotateY(-PI/4.)) 126 | .transform(Transformation::Translate(-0.5, 0., 0.5)) 127 | , 128 | ]) 129 | 130 | .transform(Transformation::Scale(0.1, 0.1, 0.1)) 131 | .transform(Transformation::Scale(10., 10., 10.)).start_t(8.25).end_t(9.75) 132 | .transform(Transformation::RotateY(PI/4.)).start_t(72.58).end_t(72.86).evolution_t(Evolution::FastIn) 133 | 134 | .transform(Transformation::RotateY(4.*PI)).start_t(9.25).end_t(14.25) 135 | .transform(Transformation::RotateX(-2.*PI)).start_t(9.25).end_t(14.25) 136 | .transform(Transformation::RotateY(4.*PI)).start_t(14.25).end_t(19.25) 137 | .transform(Transformation::RotateX(-2.*PI)).start_t(14.25).end_t(19.25) 138 | .transform(Transformation::RotateY(4.*PI)).start_t(19.25).end_t(24.25) 139 | .transform(Transformation::RotateX(-2.*PI)).start_t(19.25).end_t(24.25) 140 | .transform(Transformation::RotateY(4.*PI)).start_t(24.25).end_t(29.25) 141 | .transform(Transformation::RotateX(-2.*PI)).start_t(24.25).end_t(29.25) 142 | .transform(Transformation::RotateY(4.*PI)).start_t(29.25).end_t(34.25) 143 | .transform(Transformation::RotateX(-2.*PI)).start_t(29.25).end_t(34.25) 144 | .transform(Transformation::RotateY(4.*PI)).start_t(34.25).end_t(39.25) 145 | .transform(Transformation::RotateX(-2.*PI)).start_t(34.25).end_t(39.25) 146 | .transform(Transformation::RotateY(4.*PI)).start_t(39.25).end_t(43.) 147 | .transform(Transformation::RotateX(-2.*PI)).start_t(39.25).end_t(43.) 148 | 149 | .transform(Transformation::Translate(0., 3.0, 0.)).start_t(44.).end_t(55.) 150 | .transform(Transformation::RotateX(8.*PI)).start_t(44.).end_t(55.) 151 | .transform(Transformation::Translate(0., -3.0, 0.)).start_t(55.).end_t(58.) 152 | .transform(Transformation::RotateX(-8.*PI)).start_t(55.).end_t(58.) 153 | 154 | .transform(Transformation::Translate(-4., 0., 0.)) 155 | 156 | .rotound(-6., 60.39, 60.71, true) 157 | .rotound(-6., 61.03, 61.35, true) 158 | .rotound(-2., 61.35, 61.67, false) 159 | .rotound(2., 61.67, 61.99, true) 160 | 161 | .rotound(6., 64.06, 64.38, false) 162 | .rotound(6., 64.80, 65.12, false) 163 | .rotound(2., 65.12, 65.44, true) 164 | .rotound(-2., 65.44, 65.76, false) 165 | 166 | .transform(Transformation::Translate(0., -1., 0.)).start_t(67.33).end_t(67.61).evolution_t(Evolution::FastIn) 167 | .transform(Transformation::Translate(0., 1., 0.)).start_t(68.45).end_t(68.73).evolution_t(Evolution::FastIn) 168 | 169 | .transform(Transformation::Translate(0., -2., 0.)).start_t(71.18).end_t(71.46).evolution_t(Evolution::FastIn) 170 | .transform(Transformation::Translate(0., 7., 0.)).start_t(72.58).end_t(72.86).evolution_t(Evolution::FastIn) 171 | .transform(Transformation::Translate(2., 0., 0.)).start_t(72.58).end_t(72.86).evolution_t(Evolution::FastOut) 172 | .transform(Transformation::Translate(0., -5., 0.)).start_t(72.86).end_t(73.14).evolution_t(Evolution::FastOut) 173 | .transform(Transformation::Translate(2., 0., 0.)).start_t(72.86).end_t(73.14).evolution_t(Evolution::FastIn) 174 | ; 175 | 176 | let octahedron = Model::from_models(vec![ 177 | polygon(3, [false, true, false]) 178 | .transform(Transformation::RotateZ(PI/2.)) 179 | .transform(Transformation::Translate(0., 1., 0.)) 180 | .transform(Transformation::RotateX(0.6154)) 181 | .transform(Transformation::RotateY(PI/4.)) 182 | .transform(Transformation::Translate(0.0, -1.5f32.sqrt(), 0.0)), 183 | polygon(3, [false, true, false]) 184 | .transform(Transformation::RotateZ(PI/2.)) 185 | .transform(Transformation::Translate(0., 1., 0.)) 186 | .transform(Transformation::RotateX(0.6154)) 187 | .transform(Transformation::RotateY(3.*PI/4.)) 188 | .transform(Transformation::Translate(0.0, -1.5f32.sqrt(), 0.0)), 189 | polygon(3, [false, true, false]) 190 | .transform(Transformation::RotateZ(PI/2.)) 191 | .transform(Transformation::Translate(0., 1., 0.)) 192 | .transform(Transformation::RotateX(0.6154)) 193 | .transform(Transformation::RotateY(5.*PI/4.)) 194 | .transform(Transformation::Translate(0.0, -1.5f32.sqrt(), 0.0)), 195 | polygon(3, [false, true, false]) 196 | .transform(Transformation::RotateZ(PI/2.)) 197 | .transform(Transformation::Translate(0., 1., 0.)) 198 | .transform(Transformation::RotateX(0.6154)) 199 | .transform(Transformation::RotateY(-PI/4.)) 200 | .transform(Transformation::Translate(0.0, -1.5f32.sqrt(), 0.0)), 201 | polygon(3, [false, true, false]) 202 | .transform(Transformation::RotateZ(-PI/2.)) 203 | .transform(Transformation::Translate(0., -1., 0.)) 204 | .transform(Transformation::RotateX(0.6154)) 205 | .transform(Transformation::RotateY(PI/4.)) 206 | .transform(Transformation::Translate(0.0, 1.5f32.sqrt(), 0.0)), 207 | polygon(3, [false, true, false]) 208 | .transform(Transformation::RotateZ(-PI/2.)) 209 | .transform(Transformation::Translate(0., -1., 0.)) 210 | .transform(Transformation::RotateX(0.6154)) 211 | .transform(Transformation::RotateY(3.*PI/4.)) 212 | .transform(Transformation::Translate(0.0, 1.5f32.sqrt(), 0.0)), 213 | polygon(3, [false, true, false]) 214 | .transform(Transformation::RotateZ(-PI/2.)) 215 | .transform(Transformation::Translate(0., -1., 0.)) 216 | .transform(Transformation::RotateX(0.6154)) 217 | .transform(Transformation::RotateY(5.*PI/4.)) 218 | .transform(Transformation::Translate(0.0, 1.5f32.sqrt(), 0.0)), 219 | polygon(3, [false, true, false]) 220 | .transform(Transformation::RotateZ(-PI/2.)) 221 | .transform(Transformation::Translate(0., -1., 0.)) 222 | .transform(Transformation::RotateX(0.6154)) 223 | .transform(Transformation::RotateY(-PI/4.)) 224 | .transform(Transformation::Translate(0.0, 1.5f32.sqrt(), 0.0)), 225 | ]) 226 | 227 | .transform(Transformation::Scale(0.1, 0.1, 0.1)) 228 | .transform(Transformation::Scale(10., 10., 10.)).start_t(15.5).end_t(17.) 229 | 230 | .transform(Transformation::RotateY(4.*PI)).start_t(16.5).end_t(21.5) 231 | .transform(Transformation::RotateX(-2.*PI)).start_t(16.5).end_t(21.5) 232 | .transform(Transformation::RotateY(4.*PI)).start_t(21.5).end_t(26.5) 233 | .transform(Transformation::RotateX(-2.*PI)).start_t(21.5).end_t(26.5) 234 | .transform(Transformation::RotateY(4.*PI)).start_t(26.5).end_t(31.5) 235 | .transform(Transformation::RotateX(-2.*PI)).start_t(26.5).end_t(31.5) 236 | .transform(Transformation::RotateY(4.*PI)).start_t(31.5).end_t(36.5) 237 | .transform(Transformation::RotateX(-2.*PI)).start_t(31.5).end_t(36.5) 238 | .transform(Transformation::RotateY(4.*PI)).start_t(36.5).end_t(43.) 239 | .transform(Transformation::RotateX(-2.*PI)).start_t(36.5).end_t(43.) 240 | 241 | .transform(Transformation::Translate(0., 3.0, 0.)).start_t(44.).end_t(55.) 242 | .transform(Transformation::RotateX(6.*PI)).start_t(44.).end_t(55.) 243 | .transform(Transformation::Translate(0., -3.0, 0.)).start_t(55.).end_t(58.) 244 | .transform(Transformation::RotateX(-6.*PI)).start_t(55.).end_t(58.) 245 | 246 | .rotound(2., 60.39, 60.71, true) 247 | .rotound(6., 60.71, 61.03, false) 248 | .rotound(6., 61.35, 61.67, false) 249 | .rotound(2., 61.67, 61.99, true) 250 | 251 | .rotound(-2., 64.06, 64.38, false) 252 | .rotound(-6., 64.38, 64.80, true) 253 | .rotound(-6., 65.12, 65.44, true) 254 | .rotound(-2., 65.44, 65.76, false) 255 | 256 | .transform(Transformation::Translate(0., 3., 0.)).start_t(67.05).end_t(68.17).evolution_t(Evolution::FastIn) 257 | .transform(Transformation::Translate(0., -3., 0.)).start_t(68.17).end_t(69.29).evolution_t(Evolution::FastOut) 258 | 259 | ; 260 | 261 | let dodecahedron = Model::from_models(vec![ 262 | polygon(5, [true, true, false]) 263 | .transform(Transformation::RotateZ(PI/2.)) 264 | .transform(Transformation::RotateX(PI/2.)) 265 | .transform(Transformation::Translate(0., 1.309, 0.0)) 266 | , 267 | polygon(5, [true, true, false]) 268 | .transform(Transformation::RotateZ(PI/2.)) 269 | .transform(Transformation::Translate(0., -(PI/5.).cos(), 0.)) 270 | .transform(Transformation::RotateX(-0.4636)) 271 | .transform(Transformation::Translate(0., 1.309, -(PI/5.).cos())) 272 | , 273 | polygon(5, [true, true, false]) 274 | .transform(Transformation::RotateZ(PI/2.)) 275 | .transform(Transformation::Translate(0., -(PI/5.).cos(), 0.)) 276 | .transform(Transformation::RotateX(-0.4636)) 277 | .transform(Transformation::Translate(0., 1.309, -(PI/5.).cos())) 278 | .transform(Transformation::RotateY(2.*PI/5.)) 279 | , 280 | polygon(5, [true, true, false]) 281 | .transform(Transformation::RotateZ(PI/2.)) 282 | .transform(Transformation::Translate(0., -(PI/5.).cos(), 0.)) 283 | .transform(Transformation::RotateX(-0.4636)) 284 | .transform(Transformation::Translate(0., 1.309, -(PI/5.).cos())) 285 | .transform(Transformation::RotateY(4.*PI/5.)) 286 | , 287 | polygon(5, [true, true, false]) 288 | .transform(Transformation::RotateZ(PI/2.)) 289 | .transform(Transformation::Translate(0., -(PI/5.).cos(), 0.)) 290 | .transform(Transformation::RotateX(-0.4636)) 291 | .transform(Transformation::Translate(0., 1.309, -(PI/5.).cos())) 292 | .transform(Transformation::RotateY(6.*PI/5.)) 293 | , 294 | polygon(5, [true, true, false]) 295 | .transform(Transformation::RotateZ(PI/2.)) 296 | .transform(Transformation::Translate(0., -(PI/5.).cos(), 0.)) 297 | .transform(Transformation::RotateX(-0.4636)) 298 | .transform(Transformation::Translate(0., 1.309, -(PI/5.).cos())) 299 | .transform(Transformation::RotateY(8.*PI/5.)) 300 | , 301 | polygon(5, [true, true, false]) 302 | .transform(Transformation::RotateZ(PI/2.)) 303 | .transform(Transformation::RotateX(PI/2.)) 304 | .transform(Transformation::Translate(0., 1.309, 0.0)) 305 | .transform(Transformation::RotateX(PI)) 306 | , 307 | polygon(5, [true, true, false]) 308 | .transform(Transformation::RotateZ(PI/2.)) 309 | .transform(Transformation::Translate(0., -(PI/5.).cos(), 0.)) 310 | .transform(Transformation::RotateX(-0.4636)) 311 | .transform(Transformation::Translate(0., 1.309, -(PI/5.).cos())) 312 | .transform(Transformation::RotateX(PI)) 313 | , 314 | polygon(5, [true, true, false]) 315 | .transform(Transformation::RotateZ(PI/2.)) 316 | .transform(Transformation::Translate(0., -(PI/5.).cos(), 0.)) 317 | .transform(Transformation::RotateX(-0.4636)) 318 | .transform(Transformation::Translate(0., 1.309, -(PI/5.).cos())) 319 | .transform(Transformation::RotateY(2.*PI/5.)) 320 | .transform(Transformation::RotateX(PI)) 321 | , 322 | polygon(5, [true, true, false]) 323 | .transform(Transformation::RotateZ(PI/2.)) 324 | .transform(Transformation::Translate(0., -(PI/5.).cos(), 0.)) 325 | .transform(Transformation::RotateX(-0.4636)) 326 | .transform(Transformation::Translate(0., 1.309, -(PI/5.).cos())) 327 | .transform(Transformation::RotateY(4.*PI/5.)) 328 | .transform(Transformation::RotateX(PI)) 329 | , 330 | polygon(5, [true, true, false]) 331 | .transform(Transformation::RotateZ(PI/2.)) 332 | .transform(Transformation::Translate(0., -(PI/5.).cos(), 0.)) 333 | .transform(Transformation::RotateX(-0.4636)) 334 | .transform(Transformation::Translate(0., 1.309, -(PI/5.).cos())) 335 | .transform(Transformation::RotateY(6.*PI/5.)) 336 | .transform(Transformation::RotateX(PI)) 337 | , 338 | polygon(5, [true, true, false]) 339 | .transform(Transformation::RotateZ(PI/2.)) 340 | .transform(Transformation::Translate(0., -(PI/5.).cos(), 0.)) 341 | .transform(Transformation::RotateX(-0.4636)) 342 | .transform(Transformation::Translate(0., 1.309, -(PI/5.).cos())) 343 | .transform(Transformation::RotateY(8.*PI/5.)) 344 | .transform(Transformation::RotateX(PI)) 345 | , 346 | ]) 347 | 348 | .transform(Transformation::Scale(0.07, 0.07, 0.07)) 349 | .transform(Transformation::Scale(10., 10., 10.)).start_t(22.75).end_t(24.25) 350 | 351 | .transform(Transformation::RotateY(4.*PI)).start_t(23.75).end_t(28.75) 352 | .transform(Transformation::RotateX(-2.*PI)).start_t(23.75).end_t(28.75) 353 | .transform(Transformation::RotateY(4.*PI)).start_t(28.75).end_t(33.75) 354 | .transform(Transformation::RotateX(-2.*PI)).start_t(28.75).end_t(33.75) 355 | .transform(Transformation::RotateY(4.*PI)).start_t(33.75).end_t(38.75) 356 | .transform(Transformation::RotateX(-2.*PI)).start_t(33.75).end_t(38.75) 357 | .transform(Transformation::RotateY(4.*PI)).start_t(38.75).end_t(43.) 358 | .transform(Transformation::RotateX(-2.*PI)).start_t(38.75).end_t(43.) 359 | 360 | .transform(Transformation::Translate(0., 3.0, 0.)).start_t(44.).end_t(55.) 361 | .transform(Transformation::RotateX(4.*PI)).start_t(44.).end_t(55.) 362 | .transform(Transformation::Translate(0., -3.0, 0.)).start_t(55.).end_t(58.) 363 | .transform(Transformation::RotateX(-4.*PI)).start_t(55.).end_t(58.) 364 | 365 | .transform(Transformation::Translate(4.0, 0., 0.)) 366 | 367 | .rotound(2., 60.39, 60.71, true) 368 | .rotound(-2., 60.71, 61.03, false) 369 | .rotound(-6., 61.03, 61.35, true) 370 | .rotound(-6., 61.67, 61.99, true) 371 | 372 | .rotound(-2., 64.06, 64.38, false) 373 | .rotound(2., 64.38, 64.80, true) 374 | .rotound(6., 64.80, 65.12, false) 375 | .rotound(6., 65.44, 65.76, false) 376 | 377 | .transform(Transformation::Translate(0., -1., 0.)).start_t(67.61).end_t(67.89).evolution_t(Evolution::FastIn) 378 | .transform(Transformation::Translate(0., 1., 0.)).start_t(68.73).end_t(69.01).evolution_t(Evolution::FastIn) 379 | 380 | .transform(Transformation::Translate(0., -2., 0.)).start_t(71.46).end_t(71.74).evolution_t(Evolution::FastIn) 381 | .transform(Transformation::Translate(0., 7., 0.)).start_t(72.30).end_t(72.58).evolution_t(Evolution::FastIn) 382 | .transform(Transformation::Translate(-2., 0., 0.)).start_t(72.30).end_t(72.58).evolution_t(Evolution::FastOut) 383 | .transform(Transformation::Translate(0., -5., 0.)).start_t(72.58).end_t(72.86).evolution_t(Evolution::FastOut) 384 | .transform(Transformation::Translate(-2., 0., 0.)).start_t(72.58).end_t(72.86).evolution_t(Evolution::FastIn) 385 | ; 386 | 387 | let icosahedron = Model::from_models(vec![ 388 | polygon(3, [true, false, false]) 389 | .transform(Transformation::RotateZ(-PI/2.)) 390 | .transform(Transformation::RotateX(0.18)) 391 | .transform(Transformation::Translate(0., -0.25, -1.265)) 392 | .transform(Transformation::RotateY(PI/5.)) 393 | , 394 | polygon(3, [true, false, false]) 395 | .transform(Transformation::RotateZ(-PI/2.)) 396 | .transform(Transformation::RotateX(0.18)) 397 | .transform(Transformation::Translate(0., -0.25, -1.265)) 398 | .transform(Transformation::RotateY(3.*PI/5.)) 399 | , 400 | polygon(3, [true, false, false]) 401 | .transform(Transformation::RotateZ(-PI/2.)) 402 | .transform(Transformation::RotateX(0.18)) 403 | .transform(Transformation::Translate(0., -0.25, -1.265)) 404 | .transform(Transformation::RotateY(5.*PI/5.)) 405 | , 406 | polygon(3, [true, false, false]) 407 | .transform(Transformation::RotateZ(-PI/2.)) 408 | .transform(Transformation::RotateX(0.18)) 409 | .transform(Transformation::Translate(0., -0.25, -1.265)) 410 | .transform(Transformation::RotateY(7.*PI/5.)) 411 | , 412 | polygon(3, [true, false, false]) 413 | .transform(Transformation::RotateZ(-PI/2.)) 414 | .transform(Transformation::RotateX(0.18)) 415 | .transform(Transformation::Translate(0., -0.25, -1.265)) 416 | .transform(Transformation::RotateY(9.*PI/5.)) 417 | , 418 | 419 | polygon(3, [true, false, false]) 420 | .transform(Transformation::RotateZ(-PI/2.)) 421 | .transform(Transformation::Translate(0., 0., -1.308)) 422 | .transform(Transformation::RotateX(-0.918)) 423 | , 424 | polygon(3, [true, false, false]) 425 | .transform(Transformation::RotateZ(-PI/2.)) 426 | .transform(Transformation::Translate(0., 0., -1.308)) 427 | .transform(Transformation::RotateX(-0.918)) 428 | .transform(Transformation::RotateY(2.*PI/5.)) 429 | , 430 | polygon(3, [true, false, false]) 431 | .transform(Transformation::RotateZ(-PI/2.)) 432 | .transform(Transformation::Translate(0., 0., -1.308)) 433 | .transform(Transformation::RotateX(-0.918)) 434 | .transform(Transformation::RotateY(4.*PI/5.)) 435 | , 436 | polygon(3, [true, false, false]) 437 | .transform(Transformation::RotateZ(-PI/2.)) 438 | .transform(Transformation::Translate(0., 0., -1.308)) 439 | .transform(Transformation::RotateX(-0.918)) 440 | .transform(Transformation::RotateY(6.*PI/5.)) 441 | , 442 | polygon(3, [true, false, false]) 443 | .transform(Transformation::RotateZ(-PI/2.)) 444 | .transform(Transformation::Translate(0., 0., -1.308)) 445 | .transform(Transformation::RotateX(-0.918)) 446 | .transform(Transformation::RotateY(8.*PI/5.)) 447 | , 448 | 449 | polygon(3, [true, false, false]) 450 | .transform(Transformation::RotateZ(-PI/2.)) 451 | .transform(Transformation::RotateX(0.18)) 452 | .transform(Transformation::Translate(0., -0.25, -1.265)) 453 | .transform(Transformation::RotateY(PI/5.)) 454 | .transform(Transformation::RotateX(PI)) 455 | , 456 | polygon(3, [true, false, false]) 457 | .transform(Transformation::RotateZ(-PI/2.)) 458 | .transform(Transformation::RotateX(0.18)) 459 | .transform(Transformation::Translate(0., -0.25, -1.265)) 460 | .transform(Transformation::RotateY(3.*PI/5.)) 461 | .transform(Transformation::RotateX(PI)) 462 | , 463 | polygon(3, [true, false, false]) 464 | .transform(Transformation::RotateZ(-PI/2.)) 465 | .transform(Transformation::RotateX(0.18)) 466 | .transform(Transformation::Translate(0., -0.25, -1.265)) 467 | .transform(Transformation::RotateY(5.*PI/5.)) 468 | .transform(Transformation::RotateX(PI)) 469 | , 470 | polygon(3, [true, false, false]) 471 | .transform(Transformation::RotateZ(-PI/2.)) 472 | .transform(Transformation::RotateX(0.18)) 473 | .transform(Transformation::Translate(0., -0.25, -1.265)) 474 | .transform(Transformation::RotateY(7.*PI/5.)) 475 | .transform(Transformation::RotateX(PI)) 476 | , 477 | polygon(3, [true, false, false]) 478 | .transform(Transformation::RotateZ(-PI/2.)) 479 | .transform(Transformation::RotateX(0.18)) 480 | .transform(Transformation::Translate(0., -0.25, -1.265)) 481 | .transform(Transformation::RotateY(9.*PI/5.)) 482 | .transform(Transformation::RotateX(PI)) 483 | , 484 | 485 | polygon(3, [true, false, false]) 486 | .transform(Transformation::RotateZ(-PI/2.)) 487 | .transform(Transformation::Translate(0., 0., -1.308)) 488 | .transform(Transformation::RotateX(-0.918)) 489 | .transform(Transformation::RotateX(PI)) 490 | , 491 | polygon(3, [true, false, false]) 492 | .transform(Transformation::RotateZ(-PI/2.)) 493 | .transform(Transformation::Translate(0., 0., -1.308)) 494 | .transform(Transformation::RotateX(-0.918)) 495 | .transform(Transformation::RotateY(2.*PI/5.)) 496 | .transform(Transformation::RotateX(PI)) 497 | , 498 | polygon(3, [true, false, false]) 499 | .transform(Transformation::RotateZ(-PI/2.)) 500 | .transform(Transformation::Translate(0., 0., -1.308)) 501 | .transform(Transformation::RotateX(-0.918)) 502 | .transform(Transformation::RotateY(4.*PI/5.)) 503 | .transform(Transformation::RotateX(PI)) 504 | , 505 | polygon(3, [true, false, false]) 506 | .transform(Transformation::RotateZ(-PI/2.)) 507 | .transform(Transformation::Translate(0., 0., -1.308)) 508 | .transform(Transformation::RotateX(-0.918)) 509 | .transform(Transformation::RotateY(6.*PI/5.)) 510 | .transform(Transformation::RotateX(PI)) 511 | , 512 | polygon(3, [true, false, false]) 513 | .transform(Transformation::RotateZ(-PI/2.)) 514 | .transform(Transformation::Translate(0., 0., -1.308)) 515 | .transform(Transformation::RotateX(-0.918)) 516 | .transform(Transformation::RotateY(8.*PI/5.)) 517 | .transform(Transformation::RotateX(PI)) 518 | , 519 | ]) 520 | 521 | .transform(Transformation::Scale(0.07, 0.07, 0.07)) 522 | .transform(Transformation::Scale(10., 10., 10.)).start_t(30.).end_t(31.5) 523 | .transform(Transformation::RotateY(PI/5.)).start_t(71.74).end_t(72.30).evolution_t(Evolution::FastIn) 524 | 525 | .transform(Transformation::RotateY(4.*PI)).start_t(31.).end_t(36.) 526 | .transform(Transformation::RotateX(-2.*PI)).start_t(31.).end_t(36.) 527 | .transform(Transformation::RotateY(4.*PI)).start_t(36.).end_t(43.) 528 | .transform(Transformation::RotateX(-2.*PI)).start_t(36.).end_t(43.) 529 | 530 | .transform(Transformation::Translate(0., 3.0, 0.)).start_t(44.).end_t(55.) 531 | .transform(Transformation::RotateX(2.*PI)).start_t(44.).end_t(55.) 532 | .transform(Transformation::Translate(0., -3.0, 0.)).start_t(55.).end_t(58.) 533 | .transform(Transformation::RotateX(-2.*PI)).start_t(55.).end_t(58.) 534 | 535 | .transform(Transformation::Translate(8., 0., 0.)) 536 | 537 | .rotound(6., 60.71, 61.03, false) 538 | .rotound(2., 61.03, 61.35, true) 539 | .rotound(-2., 61.35, 61.67, false) 540 | .rotound(-6., 61.67, 61.99, true) 541 | 542 | .rotound(-6., 64.38, 64.80, true) 543 | .rotound(-2., 64.80, 65.12, false) 544 | .rotound(2., 65.12, 65.44, true) 545 | .rotound(6., 65.44, 65.76, false) 546 | 547 | .transform(Transformation::Translate(0., -1., 0.)).start_t(67.89).end_t(68.17).evolution_t(Evolution::FastIn) 548 | .transform(Transformation::Translate(0., 1., 0.)).start_t(69.01).end_t(69.29).evolution_t(Evolution::FastIn) 549 | 550 | .transform(Transformation::Translate(0., 1., 0.)).start_t(70.62).end_t(70.90).evolution_t(Evolution::FastIn) 551 | .transform(Transformation::Translate(0., -5., 0.)).start_t(71.74).end_t(72.02).evolution_t(Evolution::FastIn) 552 | .transform(Transformation::Translate(-2., 0., 0.)).start_t(71.74).end_t(72.02).evolution_t(Evolution::FastOut) 553 | .transform(Transformation::Translate(0., 2., 0.)).start_t(72.02).end_t(72.30).evolution_t(Evolution::FastOut) 554 | .transform(Transformation::Translate(-2., 0., 0.)).start_t(72.02).end_t(72.30).evolution_t(Evolution::FastIn) 555 | .transform(Transformation::Translate(0., 7., 0.)).start_t(72.30).end_t(72.58).evolution_t(Evolution::FastIn) 556 | .transform(Transformation::Translate(-2., 0., 0.)).start_t(72.30).end_t(72.58).evolution_t(Evolution::FastOut) 557 | .transform(Transformation::Translate(0., -5., 0.)).start_t(72.58).end_t(72.86).evolution_t(Evolution::FastOut) 558 | .transform(Transformation::Translate(-2., 0., 0.)).start_t(72.58).end_t(72.86).evolution_t(Evolution::FastIn) 559 | ; 560 | 561 | Input { 562 | meta: MetaInput { 563 | bg: [0.1, 0., 0.1, 1.], 564 | start: 0., 565 | end: 88., 566 | }, 567 | m: vec![ 568 | Model::from_models( 569 | vec![ 570 | tetrahedron, 571 | cube, 572 | octahedron, 573 | dodecahedron, 574 | icosahedron, // The icosahedron vertex coordinates are approximated, i couldn't figure out the correct angles. 575 | ] 576 | ) 577 | .transform(Transformation::RotateY(PI)).start_t(59.75).end_t(60.39).evolution_t(Evolution::Linear) 578 | .transform(Transformation::RotateY(-PI)).start_t(63.42).end_t(64.06).evolution_t(Evolution::Linear) 579 | .transform(Transformation::RotateY(-PI)).start_t(74.13).end_t(75.57).evolution_t(Evolution::FastOut) 580 | .transform(Transformation::Scale(2., 2., 2.)).start_t(74.13).end_t(74.85).evolution_t(Evolution::FastIn) 581 | .transform(Transformation::Scale(0., 0., 0.)).start_t(74.85).end_t(75.1).evolution_t(Evolution::FastIn) 582 | ], 583 | v: View::new() 584 | .transform(Transformation::Lookat(-8., 0., 6., -8., 0., 0., 0., 1., 0.)) 585 | 586 | .transform(Transformation::Lookat(-6., 0., 5., -8., 0., 0., 0., 1., 0.)).start_t(7.).end_t(8.).evolution_t(Evolution::Linear) 587 | .transform(Transformation::Lookat(-6., 0., 5., -4., 0., 0., 0., 1., 0.)).start_t(7.).end_t(8.).evolution_t(Evolution::Linear) 588 | .transform(Transformation::Lookat(-4., 0., 6., -4., 0., 0., 0., 1., 0.)).start_t(7.).end_t(8.).evolution_t(Evolution::Linear) 589 | .transform(Transformation::Lookat(-2., 0., 5., -4., 0., 0., 0., 1., 0.)).start_t(14.25).end_t(15.25).evolution_t(Evolution::Linear) 590 | .transform(Transformation::Lookat(-2., 0., 5., 0., 0., 0., 0., 1., 0.)).start_t(14.25).end_t(15.25).evolution_t(Evolution::Linear) 591 | .transform(Transformation::Lookat(0., 0., 6., 0., 0., 0., 0., 1., 0.)).start_t(14.25).end_t(15.25).evolution_t(Evolution::Linear) 592 | .transform(Transformation::Lookat(2., 0., 5., 0., 0., 0., 0., 1., 0.)).start_t(21.5).end_t(22.5).evolution_t(Evolution::Linear) 593 | .transform(Transformation::Lookat(2., 0., 5., 4., 0., 0., 0., 1., 0.)).start_t(21.5).end_t(22.5).evolution_t(Evolution::Linear) 594 | .transform(Transformation::Lookat(4., 0., 6., 4., 0., 0., 0., 1., 0.)).start_t(21.5).end_t(22.5).evolution_t(Evolution::Linear) 595 | .transform(Transformation::Lookat(6., 0., 5., 4., 0., 0., 0., 1., 0.)).start_t(28.75).end_t(29.75).evolution_t(Evolution::Linear) 596 | .transform(Transformation::Lookat(6., 0., 5., 8., 0., 0., 0., 1., 0.)).start_t(28.75).end_t(29.75).evolution_t(Evolution::Linear) 597 | .transform(Transformation::Lookat(8., 0., 6., 8., 0., 0., 0., 1., 0.)).start_t(28.75).end_t(29.75).evolution_t(Evolution::Linear) 598 | .transform(Transformation::Lookat(10., 0., 5., 8., 0., 0., 0., 1., 0.)).start_t(36.).end_t(37.).evolution_t(Evolution::Linear) 599 | .transform(Transformation::Lookat(10., 0., 5., 12., 0., 0., 0., 1., 0.)).start_t(36.).end_t(37.).evolution_t(Evolution::Linear) 600 | .transform(Transformation::Lookat(0., -5., 10., 0., 0., 0., 0., 1., 0.)).start_t(36.).end_t(37.).evolution_t(Evolution::FastIn) 601 | 602 | .transform(Transformation::Lookat(0., -10., 15., 0., 0., 0., 0., 1., 0.)).start_t(44.).end_t(45.).evolution_t(Evolution::FastIn) 603 | .transform(Transformation::Lookat(-12., 3., 0., -3., 0., 0., 0., 1., 0.)).start_t(44.).end_t(46.).evolution_t(Evolution::FastMiddle) 604 | .transform(Transformation::Lookat(0., 0., -10., 0., 0., 0., 0., 1., 0.)).start_t(44.).end_t(48.).evolution_t(Evolution::FastMiddle) 605 | .transform(Transformation::Lookat(15., 0., -5., 3., 0., 0., 0., 1., 0.)).start_t(44.).end_t(50.).evolution_t(Evolution::FastMiddle) 606 | .transform(Transformation::Lookat(15., 0., 0., 3., 3., 0., 0., 1., 0.)).start_t(44.).end_t(55.).evolution_t(Evolution::FastMiddle) 607 | .transform(Transformation::Lookat(18., 0., 0., 0., 0., 0., 0., 1., 0.)).start_t(55.).end_t(56.).evolution_t(Evolution::FastIn) 608 | 609 | .transform(Transformation::Lookat(0., -5., 17., 0., 0., 0., 0., 1., 0.)).start_t(57.58).end_t(59.75).evolution_t(Evolution::FastMiddle) 610 | .transform(Transformation::Lookat(0., -2.5, 8.5, 0., 0., 0., 0., 1., 0.)).start_t(71.74).end_t(73.14).evolution_t(Evolution::FastOut) 611 | , 612 | p: Projection::new().transform(Transformation::Perspective(-1., 1., -1., 1., 2., 100.)), 613 | } 614 | } 615 | 616 | fn polygon(n: u16, color_channels: [bool; 3]) -> Model { 617 | Model::from_vertices( 618 | (0..n).flat_map(|i| vec![ 619 | Vertex::new().pos(((i as f32 / n as f32) * 2. * PI).cos(), ((i as f32 / n as f32) * 2. * PI).sin(), 0.), 620 | Vertex::new().pos((((i as f32 + 1.) / n as f32) * 2. * PI).cos(), (((i as f32 + 1.) / n as f32) * 2. * PI).sin(), 0.), 621 | Vertex::new().pos(0., 0., 0.), 622 | ]).collect() 623 | ) 624 | .rgb(if color_channels[0] {(fastrand::f32()+1.)/2.} else { 0. }, if color_channels[1] {(fastrand::f32()+1.)/2.} else { 0. }, if color_channels[2] {(fastrand::f32()+1.)/2.} else { 0. }) 625 | } 626 | 627 | trait Rot { 628 | fn rotound(self: Self, x_offset: f32, start: f32, end: f32, cw: bool) -> Self; 629 | } 630 | 631 | impl Rot for Model { 632 | // Rotates linearly by pi around a y axis with an X offset from START to END CLOCKWISE 633 | fn rotound(self, x_offset: f32, start: f32, end: f32, cw: bool) -> Self { 634 | self 635 | .transform(Transformation::Translate(-x_offset, 0., 0.)).start_t(start).end_t(start) 636 | .transform(Transformation::RotateY(if cw { PI } else { -PI })).start_t(start).end_t(end).evolution_t(Evolution::Linear) 637 | .transform(Transformation::Translate(x_offset, 0., 0.)).start_t(start).end_t(start) 638 | } 639 | } -------------------------------------------------------------------------------- /examples/main/run_all.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for dir in */; do 4 | if [ -f "${dir}Cargo.toml" ]; then 5 | echo "Running cargo run in ${dir}..." 6 | cd "$dir" || exit 7 | cargo run 8 | cd .. 9 | fi 10 | done -------------------------------------------------------------------------------- /examples/main/sphere/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "sphere" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | vera-core = { path = "../../../vera-core" } 10 | vera = { path = "../../../vera" } 11 | fastrand = "2.0.1" 12 | itertools = "0.12.0" -------------------------------------------------------------------------------- /examples/main/sphere/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | 3 | use fastrand::f32; 4 | use vera::{Input, MetaInput, View, Projection, Transformation, Model, Vertex, D_TRANSFORMATION_START_TIME, D_TRANSFORMATION_END_TIME, Colorization/*, Evolution*/}; 5 | 6 | const PHI: f32 = 1.618033988749; 7 | use itertools::Itertools; 8 | use vera_core::Vera; 9 | 10 | 11 | // [Geodesic polyhedra](https://en.wikipedia.org/wiki/Geodesic_polyhedron) are a nice way of approximating a sphere with triangles. 12 | // Overall followed the method of [Dirk Bertels's paper](https://www.dirkbertels.net/computing/pentaDome.php). 13 | 14 | fn main() { 15 | let mut v = Vera::init(get()); 16 | while v.show() { 17 | v.reset(get()) 18 | }; 19 | } 20 | fn get() -> Input { 21 | // // Geodesic division of Tetrahedron, Octahedron and Icosahedron 22 | 23 | // Frequencies can generally go over 100, it's just a bit of loading after that. 24 | // let sphere1 = geodesic_sphere(tetrahedron(), 20, 2., 5.); 25 | // let sphere2 = geodesic_sphere(octahedron(), 20, 6., 9.); 26 | // let sphere3 = geodesic_sphere(icosahedron(), 20, 10., 13.); 27 | 28 | // println!("Sphere 1: Tetrahedron base"); 29 | // println!("- {} triangles.", sphere1.vertices.len()/3); 30 | // println!("- {} vertices.", (sphere1.vertices.len()+4*3)/6); // Add the number of lacking vertices for hexagonal (6) division (here: 3 per tetrahedron corner, for the 4 corners. 12 anyway). The returned geodesic sphere's vertices are all present 6 times, except the vertices of the base platonic solid. 31 | 32 | // println!("Sphere 2: Octahedron base"); 33 | // println!("- {} triangles.", sphere2.vertices.len()/3); 34 | // println!("- {} vertices.", (sphere2.vertices.len()+6*2)/6); 35 | 36 | // println!("Sphere 3: Icosahedron base"); 37 | // println!("- {} triangles.", sphere3.vertices.len()/3); 38 | // println!("- {} vertices.", (sphere3.vertices.len()+12*1)/6); 39 | 40 | // Input { 41 | // meta: MetaInput { 42 | // bg: [0.3, 0.3, 0.3, 0.3], 43 | // start: 0.0, 44 | // end: 14.0, 45 | // }, 46 | // m: vec![ 47 | // sphere1 48 | // .transform(Transformation::Scale(0.5, 0.5, 0.5)).start_t(0.0).end_t(0.0) 49 | // .transform(Transformation::Scale(2., 2., 2.)).start_t(1.0).end_t(2.0) 50 | // .transform(Transformation::Scale(0.1, 0.1, 0.1)).start_t(5.0).end_t(6.0) 51 | // .transform(Transformation::RotateY(2.*PI)).start_t(2.0).end_t(5.0), 52 | // sphere2 53 | // .transform(Transformation::Scale(0.1, 0.1, 0.1)).start_t(0.0).end_t(0.0) 54 | // .transform(Transformation::Scale(10., 10., 10.)).start_t(5.0).end_t(6.0) 55 | // .transform(Transformation::Scale(0.1, 0.1, 0.1)).start_t(9.0).end_t(10.0) 56 | // .transform(Transformation::RotateY(2.*PI)).start_t(6.0).end_t(9.0), 57 | // sphere3 58 | // .transform(Transformation::Scale(0.1, 0.1, 0.1)).start_t(0.0).end_t(0.0) 59 | // .transform(Transformation::Scale(10., 10., 10.)).start_t(9.0).end_t(10.0) 60 | // .transform(Transformation::Scale(0.2, 0.2, 0.2)).start_t(13.0).end_t(14.0) 61 | // .transform(Transformation::RotateY(2.*PI)).start_t(10.0).end_t(13.0), 62 | // ], 63 | // v: View::new().transform(Transformation::Lookat(0., 0., -3., 0., 0., 0., 0., -1., 0.)), 64 | // p: Projection::new().transform(Transformation::Perspective(-0.1, 0.1, -0.1, 0.1, 0.2, 100.)), 65 | // } 66 | 67 | 68 | 69 | 70 | // // Triangle / Arrow / Sphere scene. 71 | // 72 | // unsafe { 73 | // D_TRANSFORMATION_START_TIME = -1.; 74 | // D_TRANSFORMATION_END_TIME = -1.; 75 | // D_COLORIZATION_START_TIME = -1.; 76 | // D_COLORIZATION_END_TIME = -1.; 77 | // } 78 | // 79 | // // Frequencies can generally go over 100, it's just a bit of loading after that. 80 | // let triangle = Model::from_vertices(vec![ 81 | // Vertex::new().pos(-2.0, -0.25, 0.0).rgba(1.0, 0.0, 0.0, 1.0) 82 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(0.).end_c(2.) 83 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(2.).end_c(4.) 84 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(4.).end_c(6.) 85 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(6.).end_c(8.) 86 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(8.).end_c(10.), 87 | // Vertex::new().pos(-1.0, -0.25, 0.0).rgba(1.0, 0.0, 0.0, 1.0) 88 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(0.).end_c(2.) 89 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(2.).end_c(4.) 90 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(4.).end_c(6.) 91 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(6.).end_c(8.) 92 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(8.).end_c(10.), 93 | // Vertex::new().pos(-1.5, 0.5, 0.0).rgba(1.0, 0.0, 0.0, 1.0) 94 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(0.).end_c(2.) 95 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(2.).end_c(4.) 96 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(4.).end_c(6.) 97 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(6.).end_c(8.) 98 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(8.).end_c(10.), 99 | // ]) 100 | // .transform(Transformation::Translate(0.0, -0.125, 0.0)); 101 | // 102 | // let arrow = Model::from_vertices(vec![ 103 | // Vertex::new().pos(-0.35, -0.05, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 104 | // Vertex::new().pos(-0.35, 0.05, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 105 | // Vertex::new().pos( 0.25, -0.05, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 106 | // Vertex::new().pos(-0.35, 0.05, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 107 | // Vertex::new().pos( 0.25, -0.05, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 108 | // Vertex::new().pos( 0.25, 0.05, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 109 | // 110 | // Vertex::new().pos( 0.35, 0.00, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 111 | // Vertex::new().pos( 0.25, 0.00, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 112 | // Vertex::new().pos( 0.20, 0.15, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 113 | // Vertex::new().pos( 0.25, 0.00, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 114 | // Vertex::new().pos( 0.20, 0.15, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 115 | // Vertex::new().pos( 0.10, 0.15, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 116 | // 117 | // Vertex::new().pos( 0.35, 0.00, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 118 | // Vertex::new().pos( 0.25, 0.00, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 119 | // Vertex::new().pos( 0.20, -0.15, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 120 | // Vertex::new().pos( 0.25, 0.00, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 121 | // Vertex::new().pos( 0.20, -0.15, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 122 | // Vertex::new().pos( 0.10, -0.15, 0.0).rgba(1.0, 0.0, 0.0, 1.0), 123 | // ]); 124 | // 125 | // let sphere = geodesic_sphere(icosahedron(), 50, -1., -1.) 126 | // .recolor(Colorization::ToColor(1., 0., 0., 1.)) 127 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(0.).end_c(1.) 128 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(1.).end_c(2.) 129 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(2.).end_c(3.) 130 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(3.).end_c(4.) 131 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(4.).end_c(5.) 132 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(5.).end_c(6.) 133 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(6.).end_c(7.) 134 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(7.).end_c(8.) 135 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(8.).end_c(9.) 136 | // .recolor(Colorization::ToColor(1., f32(), f32(), 1.)).start_c(9.).end_c(10.) 137 | // .transform(Transformation::Scale(0.5, 0.5, 0.5)) 138 | // .transform(Transformation::Translate(1.5, 0.0, 0.0)); 139 | // 140 | // Input { 141 | // meta: MetaInput { 142 | // bg: [0.1, 0.1, 0.1, 0.1], 143 | // start: -1.0, 144 | // end: 11.0, 145 | // }, 146 | // m: vec![ 147 | // triangle 148 | // .transform(Transformation::Scale(0.0001, 0.0001, 0.0001)).transform(Transformation::Scale(10000.0, 10000.0, 10000.0)).start_t(0.).end_t(1.).evolution_t(Evolution::FastIn).transform(Transformation::RotateY(-3.0 * PI)).start_t(0.).end_t(10.).evolution_t(Evolution::FastMiddle).transform(Transformation::Scale(0.0001, 0.0001, 0.0001)).start_t(9.).end_t(10.).evolution_t(Evolution::FastOut), 149 | // arrow 150 | // .transform(Transformation::Scale(0.0001, 0.0001, 0.0001)).transform(Transformation::Scale(10000.0, 10000.0, 10000.0)).start_t(0.).end_t(1.).evolution_t(Evolution::FastIn).transform(Transformation::RotateY(-3.0 * PI)).start_t(0.).end_t(10.).evolution_t(Evolution::FastMiddle).transform(Transformation::Scale(0.0001, 0.0001, 0.0001)).start_t(9.).end_t(10.).evolution_t(Evolution::FastOut), 151 | // sphere 152 | // .transform(Transformation::Scale(0.0001, 0.0001, 0.0001)).transform(Transformation::Scale(10000.0, 10000.0, 10000.0)).start_t(0.).end_t(1.).evolution_t(Evolution::FastIn).transform(Transformation::RotateY(-3.0 * PI)).start_t(0.).end_t(10.).evolution_t(Evolution::FastMiddle).transform(Transformation::Scale(0.0001, 0.0001, 0.0001)).start_t(9.).end_t(10.).evolution_t(Evolution::FastOut), 153 | // ], 154 | // v: View::new().transform(Transformation::Lookat(0., 0., -3., 0., 0., 0., 0., -1., 0.)), 155 | // p: Projection::new().transform(Transformation::Perspective(-0.1, 0.1, -0.1, 0.1, 0.2, 100.)), 156 | // } 157 | 158 | 159 | 160 | 161 | // Display Icosahedron, divided with a frequency of 8. 162 | 163 | unsafe { 164 | D_TRANSFORMATION_START_TIME = 0.; 165 | D_TRANSFORMATION_END_TIME = 0.; 166 | } 167 | 168 | // let sphere1 = geodesic_sphere(icosahedron(), 1, 0., 0.); 169 | // let sphere2 = geodesic_sphere(icosahedron(), 2, 0., 0.); 170 | // let sphere3 = geodesic_sphere(icosahedron(), 3, 0., 0.); 171 | // let sphere4 = geodesic_sphere(icosahedron(), 4, 0., 0.); 172 | // let sphere5 = geodesic_sphere(icosahedron(), 5, 0., 0.); 173 | // let sphere6 = geodesic_sphere(icosahedron(), 6, 0., 0.); 174 | // let sphere7 = geodesic_sphere(icosahedron(), 7, 0., 0.); 175 | let sphere8 = geodesic_sphere(icosahedron(), 8, 0., 5.); 176 | // let sphere9 = geodesic_sphere(icosahedron(), 9, 0., 0.); 177 | // let sphere10 = geodesic_sphere(icosahedron(), 10, 0., 0.); 178 | // let sphere11 = geodesic_sphere(icosahedron(), 11, 0., 0.); 179 | // let sphere12 = geodesic_sphere(icosahedron(), 12, 0., 0.); 180 | // let sphere13 = geodesic_sphere(icosahedron(), 13, 0., 0.); 181 | // let sphere14 = geodesic_sphere(icosahedron(), 14, 0., 0.); 182 | // let sphere15 = geodesic_sphere(icosahedron(), 15, 0., 0.); 183 | // let sphere16 = geodesic_sphere(icosahedron(), 16, 0., 0.); 184 | // let sphere17 = geodesic_sphere(icosahedron(), 17, 0., 0.); 185 | // let sphere18 = geodesic_sphere(icosahedron(), 18, 0., 0.); 186 | // let sphere19 = geodesic_sphere(icosahedron(), 19, 0., 0.); 187 | 188 | Input { 189 | meta: MetaInput { 190 | bg: [0.1, 0.1, 0.1, 0.1], 191 | start: 0.0, 192 | end: 10.0, 193 | }, 194 | m: vec![ 195 | // sphere1 196 | // .transform(Transformation::Scale(0.5, 0.5, 0.5)).start_t(0.0).end_t(0.0) 197 | // .transform(Transformation::Scale(2., 2., 2.)).start_t(1.0).end_t(2.0) 198 | // .transform(Transformation::Scale(0.1, 0.1, 0.1)).start_t(5.0).end_t(6.0) 199 | // .transform(Transformation::RotateY(2.*PI)).start_t(2.0).end_t(5.0), 200 | // sphere2 201 | // .transform(Transformation::Scale(0.1, 0.1, 0.1)).start_t(0.0).end_t(0.0) 202 | // .transform(Transformation::Scale(10., 10., 10.)).start_t(5.0).end_t(6.0) 203 | // .transform(Transformation::Scale(0.1, 0.1, 0.1)).start_t(9.0).end_t(10.0) 204 | // .transform(Transformation::RotateY(2.*PI)).start_t(6.0).end_t(9.0), 205 | // sphere3 206 | // .transform(Transformation::Scale(0.1, 0.1, 0.1)).start_t(0.0).end_t(0.0) 207 | // .transform(Transformation::Scale(10., 10., 10.)).start_t(9.0).end_t(10.0) 208 | // .transform(Transformation::Scale(0.2, 0.2, 0.2)).start_t(13.0).end_t(14.0) 209 | // .transform(Transformation::RotateY(2.*PI)).start_t(10.0).end_t(13.0), 210 | 211 | // sphere1, 212 | // sphere2, 213 | // sphere3, 214 | // sphere4, 215 | // sphere5, 216 | // sphere6, 217 | // sphere7, 218 | sphere8.transform(Transformation::RotateY(PI * 4.0)).start_t(0.).end_t(10.0).evolution_t(vera::Evolution::FastMiddle), 219 | // sphere9, 220 | // sphere10, 221 | // sphere11, 222 | // sphere12, 223 | // sphere13, 224 | // sphere14, 225 | // sphere15, 226 | // sphere16, 227 | // sphere17, 228 | // sphere18, 229 | // sphere19, 230 | ], 231 | v: View::new().transform(Transformation::Lookat(0., 0., -3., 0., 0., 0., 0., -1., 0.)), 232 | p: Projection::new().transform(Transformation::Perspective(-0.1, 0.1, -0.1, 0.1, 0.2, 100.)), 233 | } 234 | } 235 | 236 | 237 | // Vizualize the geodesic vertices division indices like this (this is a frequency of 5): 238 | // 15 15 239 | // 10 /\ 16 240 | // 06 /\/\ 17 241 | // 03 /\/\/\ 18 242 | // 01 /\/\/\/\ 19 243 | // 00 /\/\/\/\/\ 20 244 | 245 | /// Modifies the given BASE_MODEL to a geodesic sphere with the given FREQUENCY. 246 | /// Returns the modified model as well as the number of triangles in it in total. 247 | /// - `base_model` is expected to contain only vertices, a number of them which is a multiple of 3, and to either be 1. tetrahedron, 2. octahedron, or 3. icosahedron. The center of this base model should be the world origin. 248 | fn geodesic_sphere(base_model: Model, frequency: u32, start: f32, end: f32) -> Model { 249 | let ( 250 | models, 251 | vertices, 252 | t, 253 | ) = base_model.own_fields(); 254 | 255 | assert!( 256 | frequency != 0 && 257 | models.is_empty() && 258 | !vertices.is_empty() && 259 | vertices.len()%3 == 0 260 | ); 261 | 262 | // The number of lines the subtriangles form (in the case of layer 0, it is a point) 263 | let layers = frequency+1; 264 | 265 | let sample_pos = vertices[0].read_position(); 266 | let radius: f32 = (sample_pos[0].powi(2) + sample_pos[1].powi(2) + sample_pos[2].powi(2)).sqrt(); 267 | 268 | let subpoints = ((frequency+1) * (frequency+2) / 2) as usize; 269 | let mut projection_multipliers: Vec = Vec::with_capacity(subpoints); 270 | 271 | let all_vertices: Vec = vertices.into_iter().chunks(3).into_iter().enumerate().flat_map(|(base_triangle_i, mut v)| { 272 | // Finding all vertices 273 | // The following iterates through each layer and each of its points to find the vertices and their coordinates. 274 | let face_red = (f32()+1.)/2.; 275 | 276 | let mut vertices: Vec = Vec::with_capacity(subpoints); 277 | let mut subvertex_i = 0; 278 | 279 | let v0 = v.next().unwrap(); 280 | let v1 = v.next().unwrap(); 281 | let v2 = v.next().unwrap(); 282 | if base_triangle_i==0 { // First time, calculates the projection multipliers 283 | 284 | // Layer 0 285 | vertices.push(v0.clone().transform(Transformation::Scale(1., 1., 1.)).start_t(start).end_t(end)); 286 | projection_multipliers.push(1.0); 287 | 288 | // Layers 1 to `frequency`-1 289 | // => Done only if (frequency > 1 (<=> max_proj_i > 0)). 290 | for layer_i in 1..layers-1 { 291 | let layer_points = layer_i+1; 292 | let unprojected_first: Vertex = new_vertex_unprojected(&v0, &v1, layer_i, layers-1); 293 | let unprojected_last: Vertex = new_vertex_unprojected(&v0, &v2, layer_i, layers-1); 294 | let new_mult = radius/(unprojected_first.read_position()[0].powi(2) + unprojected_first.read_position()[1].powi(2) + unprojected_first.read_position()[2].powi(2)).sqrt(); 295 | 296 | // Point 0 297 | vertices.push(unprojected_first.duplicate().transform(Transformation::Scale(new_mult, new_mult, new_mult)).start_t(start).end_t(end)); 298 | projection_multipliers.push(new_mult); 299 | 300 | // Points 1 to penultimate 301 | for point_i in 1..layer_points-1 { 302 | let unprojected_point = new_vertex_unprojected(&unprojected_first, &unprojected_last, point_i, layer_points-1); 303 | let new_mult = radius/(unprojected_point.read_position()[0].powi(2) + unprojected_point.read_position()[1].powi(2) + unprojected_point.read_position()[2].powi(2)).sqrt(); 304 | vertices.push(unprojected_point.transform(Transformation::Scale(new_mult, new_mult, new_mult)).start_t(start).end_t(end)); 305 | projection_multipliers.push(new_mult); 306 | } 307 | 308 | // Last point 309 | vertices.push(unprojected_last.duplicate().transform(Transformation::Scale(new_mult, new_mult, new_mult)).start_t(start).end_t(end)); 310 | projection_multipliers.push(new_mult); 311 | } 312 | 313 | // Last layer 314 | 315 | // Point 0 316 | vertices.push(v1.duplicate().transform(Transformation::Scale(1., 1., 1.)).start_t(start).end_t(end)); 317 | projection_multipliers.push(1.0); 318 | 319 | // Points 1 to penultimate 320 | let layer_points = layers; 321 | for point_i in 1..layer_points-1 { 322 | let unprojected_point = new_vertex_unprojected(&v1, &v2, point_i, layer_points-1); 323 | let new_mult = radius/(unprojected_point.read_position()[0].powi(2) + unprojected_point.read_position()[1].powi(2) + unprojected_point.read_position()[2].powi(2)).sqrt(); 324 | vertices.push(unprojected_point.transform(Transformation::Scale(new_mult, new_mult, new_mult)).start_t(start).end_t(end)); 325 | projection_multipliers.push(new_mult); 326 | } 327 | 328 | // Last point 329 | vertices.push(v2.transform(Transformation::Scale(1., 1., 1.)).start_t(start).end_t(end)); 330 | assert!(vertices.len()>0); 331 | projection_multipliers.push(1.0); 332 | 333 | // indices of the vertices of the triangle (only one OR 1 in 3) that will be the biggest after projection. 334 | if frequency>0 { 335 | let most_projected_triangle_layer_i: usize = (frequency as isize/3*2-1 + frequency as isize%3) as usize; 336 | let indices: (usize, usize, usize) = match most_projected_triangle_layer_i%2 { 337 | 0 => ( 338 | most_projected_triangle_layer_i*(most_projected_triangle_layer_i+2)/2, 339 | most_projected_triangle_layer_i*(most_projected_triangle_layer_i+2)/2 + most_projected_triangle_layer_i+1, 340 | most_projected_triangle_layer_i*(most_projected_triangle_layer_i+2)/2 + most_projected_triangle_layer_i+2, 341 | ), 342 | _ => ( 343 | most_projected_triangle_layer_i*(most_projected_triangle_layer_i+2)/2, 344 | most_projected_triangle_layer_i*(most_projected_triangle_layer_i+2)/2 + 1, 345 | most_projected_triangle_layer_i*(most_projected_triangle_layer_i+2)/2 + most_projected_triangle_layer_i+2, 346 | ), 347 | }; 348 | print_ratio(&vertices[indices.0], &vertices[indices.1], &vertices[indices.2], frequency); 349 | } 350 | } else { // Every other time, optimized. 351 | // Layer 0 352 | vertices.push(v0.duplicate()); 353 | subvertex_i+=1; 354 | 355 | // Layers 1 to `frequency`-1 356 | // => Done only if (frequency > 1 (<=> max_proj_i > 0)). 357 | for layer_i in 1..layers-1 { 358 | let layer_points = layer_i+1; 359 | 360 | let unprojected_first: Vertex = new_vertex_unprojected(&v0, &v1, layer_i, layers-1); 361 | let unprojected_last: Vertex = new_vertex_unprojected(&v0, &v2, layer_i, layers-1); 362 | 363 | // Point 0 364 | let mult = projection_multipliers[subvertex_i]; 365 | vertices.push(unprojected_first.duplicate().transform(Transformation::Scale(mult, mult, mult)).start_t(start).end_t(end)); 366 | subvertex_i+=1; 367 | 368 | // Points 1 to penultimate 369 | for point_i in 1..layer_points-1 { 370 | let mult = projection_multipliers[subvertex_i]; 371 | vertices.push(new_vertex_unprojected(&unprojected_first, &unprojected_last, point_i, layer_points-1).transform(Transformation::Scale(mult, mult, mult)).start_t(start).end_t(end)); 372 | subvertex_i+=1; 373 | } 374 | 375 | // Last point 376 | vertices.push(unprojected_last.duplicate().transform(Transformation::Scale(mult, mult, mult)).start_t(start).end_t(end)); 377 | subvertex_i+=1; 378 | } 379 | 380 | // Last layer 381 | 382 | // Point 0 383 | vertices.push(v1.duplicate()); 384 | subvertex_i+=1; 385 | 386 | // Points 1 to penultimate 387 | let layer_points = layers; 388 | for point_i in 1..layer_points-1 { 389 | let mult = projection_multipliers[subvertex_i]; 390 | vertices.push(new_vertex_unprojected(&v1, &v2, point_i, layer_points-1).transform(Transformation::Scale(mult, mult, mult)).start_t(start).end_t(end)); 391 | subvertex_i+=1; 392 | } 393 | 394 | // Last point 395 | vertices.push(v2); 396 | subvertex_i+=1; 397 | 398 | assert!(subpoints==subvertex_i); 399 | } 400 | 401 | 402 | // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 403 | 404 | // Organizing all vertices into triangles 405 | 406 | let mut triangles: Vec = vec![]; 407 | 408 | for layer_i in 0..layers-1 { 409 | let subface_red = (f32()+1.)/2.; 410 | let first_point = (layer_i) * (layer_i+1) / 2; 411 | let next_first_point = (layer_i+1) * (layer_i+2) / 2; 412 | // First triangle of the layer 413 | triangles.push(vertices[(first_point) as usize].clone().rgba(face_red, 0., 0., 1.0).recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 414 | triangles.push(vertices[(next_first_point) as usize].clone().rgba(face_red, 0., 0., 1.0).recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 415 | triangles.push(vertices[(next_first_point + 1) as usize].clone().rgba(face_red, 0., 0., 1.0).recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 416 | 417 | // Every other pair of triangles in the layer (the 2 triangles that vertex belongs to, that are on the right of that vertex on the above pyramid vizualization) 418 | for point_added_i in 0..(next_first_point-first_point-1) { 419 | let subface_red = (f32()+1.)/2.; 420 | triangles.push(vertices[(point_added_i + first_point) as usize].clone().rgba(face_red, 0., 0., 1.0).recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 421 | triangles.push(vertices[(point_added_i + first_point + 1) as usize].clone().rgba(face_red, 0., 0., 1.0).recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 422 | triangles.push(vertices[(point_added_i + next_first_point + 1) as usize].clone().rgba(face_red, 0., 0., 1.0).recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 423 | 424 | let subface_red = (f32()+1.)/2.; 425 | triangles.push(vertices[(point_added_i + first_point + 1) as usize].clone().rgba(face_red, 0., 0., 1.0).recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 426 | triangles.push(vertices[(point_added_i + next_first_point + 1) as usize].clone().rgba(face_red, 0., 0., 1.0).recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 427 | triangles.push(vertices[(point_added_i + next_first_point + 2) as usize].clone().rgba(face_red, 0., 0., 1.0).recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 428 | } 429 | } 430 | 431 | triangles 432 | }).collect(); 433 | 434 | let mut out = Model::from_vertices(all_vertices); 435 | out.set_t(t); 436 | out 437 | } 438 | 439 | /// Prints the ratio between the lowest point on the geodesic sphere and the sphere radius 440 | fn print_ratio(v1: &Vertex, v2: &Vertex, v3: &Vertex, freq: u32) { 441 | let end_pos_1 = end_position(v1); 442 | let end_pos_2 = end_position(v2); 443 | let end_pos_3 = end_position(v3); 444 | 445 | let max_dist = (end_pos_1[0].powi(2)+end_pos_1[1].powi(2)+end_pos_1[2].powi(2)).sqrt(); 446 | let min_dist = projected_origin_distance(end_pos_1, end_pos_2, end_pos_3); 447 | 448 | assert!(min_dist [f32; 3] { 455 | if let Transformation::Scale(factor, _, _) = *v.read_tf()[0].read_t() { 456 | [ 457 | v.read_position()[0] * factor, 458 | v.read_position()[1] * factor, 459 | v.read_position()[2] * factor 460 | ] 461 | } else { [0., 0., 0.] } 462 | } 463 | 464 | fn projected_origin_distance(v1: [f32; 3], v2: [f32; 3], v3: [f32; 3]) -> f32 { 465 | let vec_ab = [v2[0] - v1[0], v2[1] - v1[1], v2[2] - v1[2]]; 466 | let vec_ac = [v3[0] - v1[0], v3[1] - v1[1], v3[2] - v1[2]]; 467 | 468 | let normal_vector = [ 469 | vec_ab[1] * vec_ac[2] - vec_ac[1] * vec_ab[2], 470 | vec_ab[2] * vec_ac[0] - vec_ac[2] * vec_ab[0], 471 | vec_ab[0] * vec_ac[1] - vec_ac[0] * vec_ab[1], 472 | ]; 473 | 474 | let distance = f32::abs( 475 | normal_vector[0] * v1[0] + normal_vector[1] * v1[1] + normal_vector[2] * v1[2] 476 | ) / (normal_vector[0].powi(2) + normal_vector[1].powi(2) + normal_vector[2].powi(2)).sqrt(); 477 | 478 | distance 479 | } 480 | 481 | // TODO Remove and specify the timing of each interior frequency to `geodesic_sphere`. 482 | /// Same as geodesic_sphere, but expects `base_model` to be any geodesic sphere. The difference is that no optimizations will be made here (although there could be, but different ones). 483 | #[allow(unused)] 484 | fn refine_sphere(base_model: Model, frequency: u32, start: f32, end: f32) -> Model { 485 | let ( 486 | models, 487 | vertices, 488 | t, 489 | ) = base_model.own_fields(); 490 | 491 | assert!( 492 | frequency != 0 && 493 | models.is_empty() && 494 | !vertices.is_empty() && 495 | vertices.len()%3 == 0 496 | ); 497 | 498 | // The number of lines the subtriangles form (in the case of layer 0, it is a point) 499 | let layers = frequency+1; 500 | 501 | let mut sample_pos = vertices[1].read_position().clone(); 502 | for t_i in vertices[1].read_tf().iter() { 503 | if let Transformation::Scale(mult, _, _) = *t[0].read_t() { 504 | sample_pos[0]*=mult; 505 | sample_pos[1]*=mult; 506 | sample_pos[2]*=mult; 507 | } else { 508 | println!("This code isn't meant for other transformations than scale. Be careful!"); 509 | } 510 | } 511 | let radius = (sample_pos[0].powi(2) + sample_pos[1].powi(2) + sample_pos[2].powi(2)).sqrt(); 512 | 513 | let subpoints = ((frequency+1) * (frequency+2) / 2) as usize; 514 | 515 | let all_vertices: Vec = vertices.into_iter().chunks(3).into_iter().flat_map(|mut v| { 516 | // Finding all vertices 517 | // The following iterates through each layer and each of its points to find the vertices and their coordinates. 518 | let mut vertices: Vec = Vec::with_capacity(subpoints); 519 | 520 | let v0 = v.next().unwrap(); 521 | let v1 = v.next().unwrap(); 522 | let v2 = v.next().unwrap(); 523 | 524 | // Layer 0 525 | vertices.push(v0.clone()); 526 | 527 | // Layers 1 to `frequency`-1 528 | // => Done only if (frequency > 1 (<=> max_proj_i > 0)). 529 | for layer_i in 1..layers-1 { 530 | let layer_points = layer_i+1; 531 | let unprojected_first: Vertex = new_vertex_unprojected_cloned(&v0, &v1, layer_i, layers-1); 532 | let unprojected_last: Vertex = new_vertex_unprojected_cloned(&v0, &v2, layer_i, layers-1); 533 | 534 | // Point 0 535 | vertices.push(unprojected_first.clone().scale_to_rad(radius, start, end)); 536 | 537 | // Points 1 to penultimate 538 | for point_i in 1..layer_points-1 { 539 | let unprojected_point = new_vertex_unprojected_cloned(&unprojected_first, &unprojected_last, point_i, layer_points-1); 540 | vertices.push(unprojected_point.scale_to_rad(radius, start, end)); 541 | } 542 | 543 | // Last point 544 | vertices.push(unprojected_last.clone().scale_to_rad(radius, start, end)); 545 | } 546 | 547 | // Last layer 548 | 549 | // Point 0 550 | vertices.push(v1.clone()); 551 | 552 | // Points 1 to penultimate 553 | let layer_points = layers; 554 | for point_i in 1..layer_points-1 { 555 | let unprojected_point = new_vertex_unprojected_cloned(&v1, &v2, point_i, layer_points-1); 556 | vertices.push(unprojected_point.scale_to_rad(radius, start, end)); 557 | } 558 | 559 | // Last point 560 | vertices.push(v2); 561 | 562 | 563 | // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------- 564 | 565 | // Organizing all vertices into triangles 566 | 567 | let mut triangles: Vec = vec![]; 568 | 569 | for layer_i in 0..layers-1 { 570 | let subface_red = (f32()+1.)/2.; 571 | let first_point = (layer_i) * (layer_i+1) / 2; 572 | let next_first_point = (layer_i+1) * (layer_i+2) / 2; 573 | // First triangle of the layer 574 | triangles.push(vertices[(first_point) as usize].clone().recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 575 | triangles.push(vertices[(next_first_point) as usize].clone().recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 576 | triangles.push(vertices[(next_first_point + 1) as usize].clone().recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 577 | 578 | // Every other pair of triangles in the layer (the 2 triangles that vertex belongs to, that are on the right of that vertex on the above pyramid vizualization) 579 | for point_added_i in 0..(next_first_point-first_point-1) { 580 | let subface_red = (f32()+1.)/2.; 581 | triangles.push(vertices[(point_added_i + first_point) as usize].clone().recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 582 | triangles.push(vertices[(point_added_i + first_point + 1) as usize].clone().recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 583 | triangles.push(vertices[(point_added_i + next_first_point + 1) as usize].clone().recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 584 | 585 | let subface_red = (f32()+1.)/2.; 586 | triangles.push(vertices[(point_added_i + first_point + 1) as usize].clone().recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 587 | triangles.push(vertices[(point_added_i + next_first_point + 1) as usize].clone().recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 588 | triangles.push(vertices[(point_added_i + next_first_point + 2) as usize].clone().recolor(Colorization::ToColor(subface_red, 0., 0., 1.0)).start_c(start).end_c(end)); 589 | } 590 | } 591 | 592 | triangles 593 | }).collect(); 594 | 595 | Model::from_vertices(all_vertices) 596 | } 597 | 598 | /// Returns a vertex on the line which goes from V1 to V2, at V/W. 599 | fn new_vertex_unprojected(v1: &Vertex, v2: &Vertex, v: u32, w: u32) -> Vertex { 600 | assert!(v Vertex { 610 | assert!(v Model { 622 | let mult = 1./3.0f32.sqrt(); 623 | Model::from_vertices(vec![ 624 | Vertex::new().pos(1., 1., 1.) ,Vertex::new().pos(-1., -1., 1.) ,Vertex::new().pos(-1., 1., -1.) , 625 | Vertex::new().pos(1., 1., 1.) ,Vertex::new().pos(-1., 1., -1.) ,Vertex::new().pos(1., -1., -1.) , 626 | Vertex::new().pos(1., 1., 1.) ,Vertex::new().pos(1., -1., -1.) ,Vertex::new().pos(-1., -1., 1.) , 627 | Vertex::new().pos(-1., -1., 1.) ,Vertex::new().pos(-1., 1., -1.) ,Vertex::new().pos(1., -1., -1.) , 628 | ]).transform(Transformation::Scale(mult, mult, mult)).start_t(0.).end_t(0.) 629 | } 630 | 631 | #[allow(unused)] 632 | /// The base Octahedron 633 | fn octahedron() -> Model { 634 | Model::from_vertices(vec![ 635 | Vertex::new().pos(-1., 0., 0.) ,Vertex::new().pos(0., 1., 0.) ,Vertex::new().pos(0., 0., -1.) , 636 | Vertex::new().pos(-1., 0., 0.) ,Vertex::new().pos(0., 0., -1.) ,Vertex::new().pos(0., -1., 0.) , 637 | Vertex::new().pos(-1., 0., 0.) ,Vertex::new().pos(0., -1., 0.) ,Vertex::new().pos(0., 0., 1.) , 638 | Vertex::new().pos(-1., 0., 0.) ,Vertex::new().pos(0., 0., 1.) ,Vertex::new().pos(0., 1., 0.) , 639 | 640 | Vertex::new().pos(1., 0., 0.) ,Vertex::new().pos(0., 1., 0.) ,Vertex::new().pos(0., 0., -1.) , 641 | Vertex::new().pos(1., 0., 0.) ,Vertex::new().pos(0., 0., -1.) ,Vertex::new().pos(0., -1., 0.) , 642 | Vertex::new().pos(1., 0., 0.) ,Vertex::new().pos(0., -1., 0.) ,Vertex::new().pos(0., 0., 1.) , 643 | Vertex::new().pos(1., 0., 0.) ,Vertex::new().pos(0., 0., 1.) ,Vertex::new().pos(0., 1., 0.) , 644 | ]) 645 | } 646 | 647 | /// The base Icosahedron 648 | fn icosahedron() -> Model { 649 | let mult = 1./(PHI.powi(2)+1.).sqrt(); 650 | Model::from_vertices(vec![ 651 | Vertex::new().pos(0., 1., PHI) ,Vertex::new().pos(1., PHI, 0.) ,Vertex::new().pos(-1., PHI, 0.) , 652 | Vertex::new().pos(0., 1., PHI) ,Vertex::new().pos(-1., PHI, 0.) ,Vertex::new().pos(-PHI, 0., 1.) , 653 | Vertex::new().pos(0., 1., PHI) ,Vertex::new().pos(-PHI, 0., 1.) ,Vertex::new().pos(0., -1., PHI) , 654 | Vertex::new().pos(0., 1., PHI) ,Vertex::new().pos(0., -1., PHI) ,Vertex::new().pos(PHI, 0., 1.) , 655 | Vertex::new().pos(0., 1., PHI) ,Vertex::new().pos(PHI, 0., 1.) ,Vertex::new().pos(1., PHI, 0.) , 656 | 657 | Vertex::new().pos(0., -1., PHI) ,Vertex::new().pos(-PHI, 0., 1.) ,Vertex::new().pos(-1., -PHI, 0.) , 658 | Vertex::new().pos(0., -1., PHI) ,Vertex::new().pos(-1., -PHI, 0.) ,Vertex::new().pos(1., -PHI, 0.) , 659 | Vertex::new().pos(0., -1., PHI) ,Vertex::new().pos(1., -PHI, 0.) ,Vertex::new().pos(PHI, 0., 1.) , 660 | Vertex::new().pos(0., -1., -PHI) ,Vertex::new().pos(0., 1., -PHI) ,Vertex::new().pos(PHI, 0., -1.) , 661 | Vertex::new().pos(0., -1., -PHI) ,Vertex::new().pos(PHI, 0., -1.) ,Vertex::new().pos(1., -PHI, 0.) , 662 | 663 | Vertex::new().pos(0., -1., -PHI) ,Vertex::new().pos(1., -PHI, 0.) ,Vertex::new().pos(-1., -PHI, 0.) , 664 | Vertex::new().pos(0., -1., -PHI) ,Vertex::new().pos(-1., -PHI, 0.) ,Vertex::new().pos(-PHI, 0., -1.) , 665 | Vertex::new().pos(0., -1., -PHI) ,Vertex::new().pos(-PHI, 0., -1.) ,Vertex::new().pos(0., 1., -PHI) , 666 | Vertex::new().pos(0., 1., -PHI) ,Vertex::new().pos(-PHI, 0., -1.) ,Vertex::new().pos(-1., PHI, 0.) , 667 | Vertex::new().pos(0., 1., -PHI) ,Vertex::new().pos(-1., PHI, 0.) ,Vertex::new().pos(1., PHI, 0.) , 668 | 669 | Vertex::new().pos(0., 1., -PHI) ,Vertex::new().pos(1., PHI, 0.) ,Vertex::new().pos(PHI, 0., -1.) , 670 | Vertex::new().pos(PHI, 0., 1.) ,Vertex::new().pos(1., -PHI, 0.) ,Vertex::new().pos(PHI, 0., -1.) , 671 | Vertex::new().pos(PHI, 0., 1.) ,Vertex::new().pos(PHI, 0., -1.) ,Vertex::new().pos(1., PHI, 0.) , 672 | Vertex::new().pos(-PHI, 0., 1.) ,Vertex::new().pos(-1., PHI, 0.) ,Vertex::new().pos(-PHI, 0., -1.) , 673 | Vertex::new().pos(-PHI, 0., 1.) ,Vertex::new().pos(-PHI, 0., -1.) ,Vertex::new().pos(-1., -PHI, 0.) , 674 | ]).transform(Transformation::Scale(mult, mult, mult)).start_t(0.).end_t(0.) 675 | } 676 | 677 | 678 | trait Project { 679 | fn scale_to_rad(self: Self, rad: f32, start: f32, end: f32) -> Self; 680 | } 681 | 682 | impl Project for Vertex { 683 | // Rotates linearly by pi around a y axis with an X offset from START to END CLOCKWISE 684 | fn scale_to_rad(self: Self, rad: f32, start: f32, end: f32) -> Self { 685 | let [mut x, mut y, mut z, _] = self.read_position(); 686 | self.read_tf().iter().for_each(|t| { 687 | if let Transformation::Scale(factor, _, _) = *t.read_t() { 688 | x*=factor; 689 | y*=factor; 690 | z*=factor; 691 | } 692 | }); 693 | let mult = rad/(x.powi(2) + y.powi(2) + z.powi(2)).sqrt(); 694 | self 695 | .transform(Transformation::Scale(mult, mult, mult)).start_t(start).end_t(end) 696 | } 697 | } -------------------------------------------------------------------------------- /examples/main/squares/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "squares" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | vera-core = { path = "../../../vera-core" } 10 | vera = { path = "../../../vera" } -------------------------------------------------------------------------------- /examples/main/squares/README.md: -------------------------------------------------------------------------------- 1 | # This example 2 | An animation, with squares. -------------------------------------------------------------------------------- /examples/main/squares/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | 3 | use vera::*; 4 | use vera_core::*; 5 | 6 | fn main() { 7 | let mut v = Vera::init(get()); 8 | unsafe { 9 | D_VERTEX_ALPHA = 1.0; 10 | } 11 | 12 | v.show(); 13 | } 14 | 15 | fn get() -> Input { 16 | Input { 17 | meta: MetaInput { 18 | bg: [0.1, 0.3, 0.5, 1.0], 19 | start: 0.0, 20 | end: 13.0, 21 | }, 22 | m: (0..100) 23 | .map(|n| 24 | Model::from_vertices( 25 | vec![ 26 | Vertex::new().pos(-0.5, -0.5, 0.0).rgba((99-n) as f32/99.0, 0.0, 0.0, 1.0), 27 | Vertex::new().pos(0.5, -0.5, 0.0).rgba((99-n) as f32/99.0, 0.0, 0.0, 1.0), 28 | Vertex::new().pos(-0.5, 0.5, 0.0).rgba((99-n) as f32/99.0, 0.0, 0.0, 1.0), 29 | 30 | Vertex::new().pos(0.5, 0.5, 0.0).rgba((99-n) as f32/99.0, 0.0, 0.0, 1.0), 31 | Vertex::new().pos(0.5, -0.5, 0.0).rgba((99-n) as f32/99.0, 0.0, 0.0, 1.0), 32 | Vertex::new().pos(-0.5, 0.5, 0.0).rgba((99-n) as f32/99.0, 0.0, 0.0, 1.0), 33 | ] 34 | ) 35 | .transform(Transformation::Scale(0.1, 0.1, 0.1)).start_t(1.0 + (100 - n) as f32 / 50.0).end_t(1.5 + (100 - n) as f32 / 50.0) 36 | .transform(Transformation::Scale(2.0, 2.0, 2.0)).start_t(9.0).end_t(11.0) 37 | .transform(Transformation::RotateZ(2.0 * PI)).start_t(n as f32/100.0 + 5.0).end_t(n as f32/100.0 + 7.0) 38 | .transform(Transformation::Translate(((n%10) as f32 - 4.5) / 5.0, ((n/10) as f32 - 4.5) / 5.0, 0.0)).start_t(1.0 + (100 - n) as f32 / 50.0).end_t(1.5 + (100 - n) as f32 / 50.0) 39 | ).collect(), 40 | v: View::new(), 41 | p: Projection::new(), 42 | } 43 | } 44 | 45 | -------------------------------------------------------------------------------- /examples/main/text/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "text" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | vera-core = { path = "../../../vera-core" } 10 | vera = { path = "../../../vera" } -------------------------------------------------------------------------------- /examples/main/text/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | 3 | use vera_core::Vera; 4 | use vera::{text::Text, Colorization, Evolution, Input, MetaInput, Model, Projection, ToModel, Transformation, Vertex, View}; 5 | 6 | fn main() { 7 | let mut v = Vera::init(Input { 8 | meta: MetaInput { 9 | bg: [0.1, 0.1, 0.1, 1.0], 10 | start: 0.0, 11 | end: 10.0, 12 | }, 13 | m: { 14 | let small = Text::new("Small".to_owned(), 0.1, 0.0, 1.0); 15 | let big = Text::new("Big".to_owned(), 1.0, 0.0, 1.0); 16 | let hellotext = Text::new("Hello Colored Text!".to_owned(), 1.0, 0.0, 1.0); 17 | let iamspawning: Text = Text::new("I am spawning...".to_owned(), 1.0, 0.0, 1.0); 18 | let close: Text = Text::new("I am close".to_owned(), 0.8, -0.1, 1.0); 19 | let far: Text = Text::new("I am far".to_owned(), 0.8, 0.1, 1.0); 20 | let spawningtext = iamspawning.model().alpha(0.0); 21 | vec![ 22 | small.model() 23 | .rgb(1.0, 1.0, 1.0) 24 | .transform(Transformation::Scale(1.0, -1.0, 1.0)).start_t(0.0).end_t(0.0) 25 | .transform(Transformation::Translate(0.0, -0.5, 0.0)).start_t(0.0).end_t(0.0) 26 | .transform(Transformation::Translate(-1.0, 0.0, 0.0)).start_t(5.0).end_t(7.0), 27 | big.model() 28 | .rgb(1.0, 1.0, 1.0) 29 | .transform(Transformation::Scale(1.0, -1.0, 1.0)).start_t(0.0).end_t(0.0) 30 | .transform(Transformation::Translate(-0.2, -5.5, 0.0)).start_t(0.0).end_t(0.0) 31 | .transform(Transformation::Translate(0.0, 5.2, 0.0)).start_t(6.8).end_t(7.0), 32 | hellotext.model() 33 | .transform(Transformation::Scale(0.25, -0.25, 0.25)).start_t(0.0).end_t(0.0) 34 | .transform(Transformation::Translate(-1.1, 0.0, 0.0)).start_t(0.0).end_t(0.0), 35 | close.model() 36 | .transform(Transformation::Scale(0.25, -0.25, 0.25)).start_t(0.0).end_t(0.0) 37 | .transform(Transformation::Translate(-0.9, 0.4, 0.0)).start_t(0.0).end_t(0.0), 38 | far.model() 39 | .transform(Transformation::Scale(0.25, -0.25, 0.25)).start_t(0.0).end_t(0.0) 40 | .transform(Transformation::Translate(-0.1, 0.4, 0.0)).start_t(0.0).end_t(0.0), 41 | spawningtext 42 | .transform(Transformation::Scale(0.25, -0.25, 0.25)).start_t(0.0).end_t(0.0) 43 | .transform(Transformation::Translate(-0.7, 0.7, 0.0)).start_t(0.0).end_t(0.0), 44 | ] 45 | }, 46 | v: View::new(), 47 | p: Projection::new(), 48 | }); 49 | v.show(); 50 | } -------------------------------------------------------------------------------- /examples/main/tilings/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "tilings" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | -------------------------------------------------------------------------------- /examples/main/tilings/src/main.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | println!("Hello, world!"); 3 | } 4 | -------------------------------------------------------------------------------- /examples/main/triangles/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "triangles" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 7 | 8 | [dependencies] 9 | vera-core = { path = "../../../vera-core" } 10 | vera = { path = "../../../vera" } 11 | itertools = "0.12.0" -------------------------------------------------------------------------------- /examples/main/triangles/src/main.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | use itertools::Itertools; 3 | 4 | use vera_core::Vera; 5 | use vera::{Colorization, Evolution, Input, MetaInput, Model, Projection, Transformation, Vertex, View}; 6 | 7 | fn main() { 8 | let mut v = Vera::init(Input { 9 | meta: MetaInput { 10 | bg: [0.1, 0.1, 0.1, 1.0], 11 | start: 0.0, 12 | end: 13.0, 13 | }, 14 | m: (0..2).flat_map(move |rot| { 15 | (-9..10).flat_map(move |col| { 16 | (-9..10).map(move |row| { 17 | Model::from_vertices(vec![ 18 | Vertex::new().pos(0., 1., 0.).b(1.).recolor(Colorization::ToColor(0., 0., 0., 0.)).start_c(11.0 + (10*row + col) as f32 / 100.0).end_c(11.5 + (10*row + col) as f32 / 100.0).evolution_c(Evolution::SlowIn), 19 | Vertex::new().pos(3.0f32.sqrt()/2., -0.5, 0.).b(1.).recolor(Colorization::ToColor(0., 0., 0., 0.)).start_c(11.0 + (10*row + col) as f32 / 100.0).end_c(11.5 + (10*row + col) as f32 / 100.0).evolution_c(Evolution::SlowIn), 20 | Vertex::new().pos(-3.0f32.sqrt()/2., -0.5, 0.).b(1.).recolor(Colorization::ToColor(0., 0., 0., 0.)).start_c(11.0 + (10*row + col) as f32 / 100.0).end_c(11.5 + (10*row + col) as f32 / 100.0).evolution_c(Evolution::SlowIn), 21 | ]) 22 | .transform(Transformation::Scale(0.001, 0.001, 0.001)).start_t(0.0).end_t(0.0) 23 | .transform(Transformation::Scale(1000.0, 1000.0, 1000.0)).start_t(0.0).end_t(1.5).evolution_t(Evolution::FastIn) 24 | .transform(Transformation::RotateZ(rot as f32 * PI / 3.)).start_t(5.5 - 4.0 * ((col as f32).abs() + (row as f32).abs())/20.).end_t(8.0 - 4.0 * ((col as f32).abs() + (row as f32).abs())/20.).evolution_t(Evolution::FastOut) 25 | .transform(Transformation::Translate(3.0f32.sqrt() * rot as f32 / 2.0, 0.5 * rot as f32, 0.0)).start_t(5.5 - 4.0 * ((col as f32).abs() + (row as f32).abs())/20.).end_t(8.0 - 4.0 * ((col as f32).abs() + (row as f32).abs())/20.).evolution_t(Evolution::FastOut) 26 | .transform(Transformation::Translate(col as f32 * 3.0f32.sqrt(), row as f32 * 1.5, 0.0)).start_t(5.5 - 4.0 * ((col as f32).abs() + (row as f32).abs())/20.).end_t(8.0 - 4.0 * ((col as f32).abs() + (row as f32).abs())/20.).evolution_t(Evolution::FastOut) 27 | }) 28 | }) 29 | }).collect_vec(), 30 | v: View::new().transform(Transformation::Lookat(0., 0., -3., 0., 0., 0., 0., 1., 0.)).start_t(0.).end_t(0.), 31 | p: Projection::new().transform(Transformation::Perspective(-0.1, 0.1, -0.1, 0.1, 0.1, 100.)).start_t(0.).end_t(0.), 32 | }); 33 | v.show(); 34 | } -------------------------------------------------------------------------------- /examples/tests/Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | resolver = "2" 3 | members = ["anim"] 4 | 5 | [package] 6 | name = "tests" 7 | version = "0.1.0" 8 | edition = "2021" 9 | 10 | # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html 11 | 12 | [dependencies] 13 | anim = { path = "./anim" } 14 | hot-lib-reloader = "^0.6" 15 | vera-core = { path = "../../vera-core" } 16 | vera = { path = "../../vera" } -------------------------------------------------------------------------------- /examples/tests/anim/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "anim" 3 | version = "0.1.0" 4 | edition = "2021" 5 | 6 | [lib] 7 | crate-type = ["rlib", "dylib"] 8 | 9 | [dependencies] 10 | vera = { path = "../../../vera" } -------------------------------------------------------------------------------- /examples/tests/anim/src/lib.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | 3 | use vera::{Input, MetaInput, Model, Vertex, Transformation, View, Projection, Colorization}; 4 | 5 | #[no_mangle] 6 | pub(crate) fn get() -> Input { 7 | Input { 8 | meta: MetaInput { 9 | bg: [0.0, 0.0, 0.0, 1.0], 10 | start: 0.0, 11 | end: 13.0, 12 | }, 13 | m: vec![ Model::from_models(vec![ 14 | Model::from_vertices( 15 | vec![ 16 | Vertex::new().pos(0.5, -0.5, 0.0).transform(Transformation::RotateZ(2.0*PI)).start_t(4.0).end_t(9.0), 17 | Vertex::new().pos(-0.5, -0.5, 0.0).transform(Transformation::RotateZ(4.0*PI)).start_t(5.0).end_t(8.0), 18 | Vertex::new().pos(0.0, -0.8, 0.0).transform(Transformation::RotateZ(8.0*PI)).start_t(6.0).end_t(7.0), 19 | ], 20 | ),//.transform(Transformation::RotateZ(4.0*PI)).start_t(0.0).end_t(1.0), 21 | Model::from_models( 22 | vec![ 23 | Model::from_vertices(vec![ 24 | Vertex::new().pos(0.0, 0.0, 0.0), 25 | Vertex::new().pos(0.5, -0.5, 0.0), 26 | Vertex::new().pos(0.5, 0.5, 0.0), 27 | ]), 28 | Model::from_vertices(vec![ 29 | Vertex::new().pos(0.0, 0.0, 0.0).recolor(Colorization::ToColor(0.0, 0.0, 0.0, 1.0)).start_c(1.0).end_c(10.0), 30 | Vertex::new().pos(0.5, -0.5, 0.0), 31 | Vertex::new().pos(-0.5, -0.5, 0.0), 32 | ]), 33 | ], 34 | ),//.transform(Transformation::RotateZ(4.0*PI)).start_t(0.0).end_t(1.0), 35 | Model::from_vm( 36 | vec![ 37 | Vertex::new().pos(0.5, 0.5, 0.0), 38 | Vertex::new().pos(-0.5, 0.5, 0.0), 39 | ], 40 | vec![ 41 | Model::from_vertices(vec![ 42 | Vertex::new().pos(-0.5, -0.5, 0.0), 43 | ]).transform(Transformation::RotateZ(2.0*PI)).start_t(0.0).end_t(4.0), 44 | Model::from_vertices(vec![ 45 | ]), 46 | ], 47 | ).transform(Transformation::RotateZ(2.0*PI)).start_t(0.0).end_t(4.0) 48 | ]).transform(Transformation::RotateZ(2.0*PI)).start_t(0.0).end_t(4.0)], 49 | v: View::new(), 50 | p: Projection::new(), 51 | } 52 | } -------------------------------------------------------------------------------- /examples/tests/src/main.rs: -------------------------------------------------------------------------------- 1 | use vera::D_VERTEX_ALPHA; 2 | use vera_core::*; 3 | use vera::{Input, MetaInput, Model, Vertex, Transformation, View, Projection, Colorization}; 4 | 5 | use std::f32::consts::PI; 6 | // #[hot_lib_reloader::hot_module(dylib = "anim")] 7 | // mod hot_lib { 8 | // use vera::Input; 9 | // // Path form the project root 10 | // 11 | // #[hot_function] 12 | // pub fn get() -> Input {} 13 | // } 14 | 15 | fn main() { 16 | println!("Running tests."); 17 | println!("1. Static drawing,"); 18 | println!("2. Per-vertex animation,"); 19 | println!("3. Per-model animation,"); 20 | unsafe { 21 | D_VERTEX_ALPHA = 1.0; 22 | } 23 | 24 | // Yeah, no point in having hot-reloading there ;) 25 | let mut v = Vera::init(Input { 26 | meta: MetaInput { 27 | bg: [0.0, 0.0, 0.0, 1.0], 28 | start: 0.0, 29 | end: 0.0, 30 | }, 31 | m: vec![ 32 | Model::from_vertices( 33 | vec![ 34 | Vertex::new().pos(0.5, -0.5, 0.0).transform(Transformation::RotateZ(2.0*PI)).start_t(4.0).end_t(9.0), 35 | Vertex::new().pos(-0.5, -0.5, 0.0).transform(Transformation::RotateZ(4.0*PI)).start_t(5.0).end_t(8.0), 36 | Vertex::new().pos(0.0, -0.8, 0.0).transform(Transformation::RotateZ(8.0*PI)).start_t(6.0).end_t(7.0), 37 | ], 38 | ) 39 | ], 40 | v: View::new(), 41 | p: Projection::new(), 42 | }); 43 | 44 | while v.show() { 45 | v.reset(Input { 46 | meta: MetaInput { 47 | bg: [0.0, 0.0, 0.0, 1.0], 48 | start: 0.0, 49 | end: 13.0, 50 | }, 51 | m: vec![ Model::from_models(vec![ 52 | Model::from_vertices( 53 | vec![ 54 | Vertex::new().pos(0.5, -0.5, 0.0).transform(Transformation::RotateZ(2.0*PI)).start_t(4.0).end_t(9.0), 55 | Vertex::new().pos(-0.5, -0.5, 0.0).transform(Transformation::RotateZ(4.0*PI)).start_t(5.0).end_t(8.0), 56 | Vertex::new().pos(0.0, -0.8, 0.0).transform(Transformation::RotateZ(8.0*PI)).start_t(6.0).end_t(7.0), 57 | ], 58 | ),//.transform(Transformation::RotateZ(4.0*PI)).start_t(0.0).end_t(1.0), 59 | Model::from_models( 60 | vec![ 61 | Model::from_vertices(vec![ 62 | Vertex::new().pos(0.0, 0.0, 0.0), 63 | Vertex::new().pos(0.5, -0.5, 0.0), 64 | Vertex::new().pos(0.5, 0.5, 0.0), 65 | ]), 66 | Model::from_vertices(vec![ 67 | Vertex::new().pos(0.0, 0.0, 0.0).recolor(Colorization::ToColor(0.0, 0.0, 0.0, 1.0)).start_c(1.0).end_c(10.0), 68 | Vertex::new().pos(0.5, -0.5, 0.0), 69 | Vertex::new().pos(-0.5, -0.5, 0.0), 70 | ]), 71 | ], 72 | ),//.transform(Transformation::RotateZ(4.0*PI)).start_t(0.0).end_t(1.0), 73 | Model::from_vm( 74 | vec![ 75 | Vertex::new().pos(0.5, 0.5, 0.0), 76 | Vertex::new().pos(-0.5, 0.5, 0.0), 77 | ], 78 | vec![ 79 | Model::from_vertices(vec![ 80 | Vertex::new().pos(-0.5, -0.5, 0.0), 81 | ]).transform(Transformation::RotateZ(2.0*PI)).start_t(0.0).end_t(4.0), 82 | Model::from_vertices(vec![ 83 | ]), 84 | ], 85 | ).transform(Transformation::RotateZ(2.0*PI)).start_t(0.0).end_t(4.0) 86 | ]).transform(Transformation::RotateZ(2.0*PI)).start_t(0.0).end_t(4.0)], 87 | v: View::new(), 88 | p: Projection::new(), 89 | }); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /vera-core/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "vera-core" 3 | version = "0.3.0" 4 | # author = "Coddeus" 5 | edition = "2021" 6 | license = "GPL-3.0-only" 7 | description = "Vulkan Engine in Rust for Animation" 8 | documentation = "https://docs.rs/vera-core" 9 | repository = "https://github.com/Coddeus/vera" 10 | readme = "README.md" 11 | keywords = ["animation", "vulkan", "videos", "graphics", "renderer"] 12 | categories = ["graphics", "multimedia::video", "rendering::engine"] 13 | 14 | [dependencies] 15 | vulkano = "0.34.0" 16 | vulkano-shaders = "0.34.0" 17 | vulkano-win = "0.34.0" 18 | vulkano-macros = "0.34.0" 19 | winit = "0.28.7" 20 | png = "0.17.13" 21 | 22 | vera = { version = "0.3.0", path = "../vera" } 23 | 24 | 25 | [profile.dev] 26 | opt-level = 1 27 | 28 | [profile.release] 29 | opt-level = 3 -------------------------------------------------------------------------------- /vera-core/README.md: -------------------------------------------------------------------------------- 1 | # Vera-Core 2 | The core of [the Vera engine](https://github.com/Coddeus/vera). 3 | Contains the Vulkan implementation and major user functions. -------------------------------------------------------------------------------- /vera-core/src/buffers.rs: -------------------------------------------------------------------------------- 1 | use vulkano::{buffer::BufferContents, pipeline::graphics::vertex_input::Vertex, padded::Padded}; 2 | 3 | /// A vertex with expected position and color, given as input to the graphics pipeline. 4 | #[derive(BufferContents, Vertex, Debug, Clone, Copy)] 5 | #[repr(C)] 6 | pub(crate) struct BaseVertex { 7 | /// The (x, y) [normalized-square-centered](broken_link) coordinates of this vertex. 8 | #[format(R32G32B32A32_SFLOAT)] 9 | pub(crate) position: [f32; 4], 10 | /// The rgba color of this vertex. 11 | #[format(R32G32B32A32_SFLOAT)] 12 | pub(crate) color: [f32; 4], 13 | /// The coordinates of the texture on this vertex. 14 | #[format(R32G32_SFLOAT)] 15 | pub(crate) tex_coord: [f32; 2], 16 | /// The id of the texture drawn on this vertex. 17 | #[format(R32_UINT)] 18 | pub(crate) tex_id: u32, 19 | /// The id of the entity this vertex belongs to. 20 | #[format(R32_UINT)] 21 | pub(crate) entity_id: u32, 22 | } 23 | impl Default for BaseVertex { 24 | fn default() -> Self { 25 | Self { 26 | position: [0.0, 0.0, 0.0, 1.0], 27 | color: [0.5, 1.0, 0.8, 1.0], 28 | tex_coord: [0.0, 0.0], 29 | tex_id: 0, 30 | entity_id: 0, 31 | } 32 | } 33 | } 34 | 35 | /// Matrix transformation data. 36 | #[derive(BufferContents, Debug, Clone, Copy)] 37 | #[repr(C)] 38 | pub(crate) struct MatrixT { 39 | /// The value of the transformation 40 | pub(crate) mat: [f32; 16], 41 | } 42 | 43 | /// Vector transformation data. 44 | #[derive(BufferContents, Debug)] 45 | #[repr(C)] 46 | pub(crate) struct VectorT { 47 | /// The value of the transformation 48 | pub(crate) vec: [f32; 4], 49 | } 50 | 51 | /// Per-entity data. 52 | #[derive(BufferContents, Debug)] 53 | #[repr(C)] 54 | pub(crate) struct Entity { 55 | pub(crate) parent_id: Padded, 56 | } 57 | 58 | /// A matrix transformation 59 | #[derive(BufferContents, Debug)] 60 | #[repr(C)] 61 | pub(crate) struct MatrixTransformation { 62 | /// The kind of transformation 63 | pub(crate) val: [f32; 3], 64 | pub(crate) ty: u32, 65 | pub(crate) start: f32, 66 | pub(crate) end: f32, 67 | pub(crate) evolution: Padded, 68 | } 69 | impl Default for MatrixTransformation { 70 | fn default() -> Self { 71 | Self { 72 | ty: 0, 73 | val: [0.0, 0.0, 0.0], 74 | start: 0.0, 75 | end: 0.0, 76 | evolution: Padded(0), 77 | } 78 | } 79 | } 80 | 81 | /// A color transformation 82 | #[derive(BufferContents, Debug)] 83 | #[repr(C)] 84 | pub(crate) struct ColorTransformation { 85 | pub(crate) val: [f32; 4], 86 | pub(crate) ty: u32, 87 | pub(crate) start: f32, 88 | pub(crate) end: f32, 89 | pub(crate) evolution: u32, 90 | } 91 | impl Default for ColorTransformation { 92 | fn default() -> Self { 93 | Self { 94 | val: [0.0, 0.0, 0.0, 0.0], 95 | ty: 0, 96 | start: 0.0, 97 | end: 0.0, 98 | evolution: 0, 99 | } 100 | } 101 | } 102 | 103 | /// A matrix transformer 104 | #[derive(BufferContents, Debug, Clone, Copy)] 105 | #[repr(C)] 106 | pub(crate) struct MatrixTransformer { 107 | pub(crate) mat: [f32; 16], 108 | pub(crate) range: Padded<[u32; 2], 8>, 109 | } 110 | impl MatrixTransformer { 111 | pub(crate) fn from_lo(length: u32, offset: u32) -> Self { 112 | Self { 113 | mat: [ 114 | 1.0, 0.0, 0.0, 0.0, 115 | 0.0, 1.0, 0.0, 0.0, 116 | 0.0, 0.0, 1.0, 0.0, 117 | 0.0, 0.0, 0.0, 1.0, 118 | ], 119 | range: Padded([offset, offset+length]), 120 | } 121 | } 122 | } 123 | 124 | /// A color transformer 125 | #[derive(BufferContents, Debug, Clone, Copy)] 126 | #[repr(C)] 127 | pub(crate) struct ColorTransformer { 128 | pub(crate) vec: [f32; 4], 129 | pub(crate) range: Padded<[u32; 2], 8>, 130 | } 131 | impl ColorTransformer { 132 | pub(crate) fn from_loc(length: u32, offset: u32, col: [f32; 4]) -> Self { 133 | Self { 134 | vec: col, 135 | range: Padded([offset, offset+length]), 136 | } 137 | } 138 | } 139 | 140 | /// General-purpose uniform data used in the compute shader. 141 | /// Used as push constant 142 | #[derive(Debug, Clone, BufferContents)] 143 | #[repr(C)] 144 | pub(crate) struct CSGeneral { 145 | /// The time elapsed since the beginning. 146 | pub(crate) time: f32, 147 | } 148 | 149 | /// General-purpose uniform data used in the vertex shader. 150 | /// Used as push constant 151 | #[derive(Debug, Clone, BufferContents)] 152 | #[repr(C)] 153 | pub(crate) struct VSGeneral { 154 | /// The vpr matrix (view, projection, resolution) 155 | pub(crate) mat: [f32 ; 16], 156 | } 157 | // impl Default for GeneralData { 158 | // fn default() -> Self { 159 | // Self { 160 | // mat: [ 161 | // 1.0, 0.0, 0.0, 0.0, 162 | // 0.0, 1.0, 0.0, 0.0, 163 | // 0.0, 0.0, 1.0, 0.0, 164 | // 0.0, 0.0, 0.0, 1.0, 165 | // ], 166 | // time: 0.0, 167 | // } 168 | // } 169 | // } -------------------------------------------------------------------------------- /vera-core/src/fonts/README.md: -------------------------------------------------------------------------------- 1 | # How to use a font 2 | - Create a font atlas with msdf-atlas-gen 3 | - json for texture data 4 | - goes in vera/src/extensions/text/fonts 5 | - change path in vera/src/extensions/text/font.rs 6 | - png for image atlas 7 | - goes in vera-core/src/fonts 8 | - you may change it to another color format (e.g. `ffmpeg -i cmunti_msdf_100_005.png -pix_fmt rgba cmunti_msdf_100_005_rgba.png`) 9 | - change path for texture creation in vera-core/src/lib.rs, as well as buffer size and image format (to match the new file colorspace) 10 | - Modify the shader according to the mode generated -------------------------------------------------------------------------------- /vera-core/src/fonts/cmunti_msdf_100_005.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coddeus/vera/e60fe77f32b39540b8bc5b43be026627cf615167/vera-core/src/fonts/cmunti_msdf_100_005.png -------------------------------------------------------------------------------- /vera-core/src/fonts/cmunti_msdf_100_005_rgba.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coddeus/vera/e60fe77f32b39540b8bc5b43be026627cf615167/vera-core/src/fonts/cmunti_msdf_100_005_rgba.png -------------------------------------------------------------------------------- /vera-core/src/fonts/cmunti_mtsdf_128_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coddeus/vera/e60fe77f32b39540b8bc5b43be026627cf615167/vera-core/src/fonts/cmunti_mtsdf_128_16.png -------------------------------------------------------------------------------- /vera-core/src/fonts/cmunti_sdf_128_16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coddeus/vera/e60fe77f32b39540b8bc5b43be026627cf615167/vera-core/src/fonts/cmunti_sdf_128_16.png -------------------------------------------------------------------------------- /vera-core/src/matrix.rs: -------------------------------------------------------------------------------- 1 | /// A 4x4 matrix 2 | #[repr(C)] 3 | #[derive(Clone, Copy)] 4 | pub struct Mat4(pub [f32; 16]); 5 | 6 | impl std::fmt::Debug for Mat4 { 7 | fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { 8 | write!(f, "[\n\t{}, {}, {}, {}, \n\t{}, {}, {}, {}, \n\t{}, {}, {}, {}, \n\t{}, {}, {}, {}, \n]", self.0[0], self.0[1], self.0[2], self.0[3], self.0[4], self.0[5], self.0[6], self.0[7], self.0[8], self.0[9], self.0[10], self.0[11], self.0[12], self.0[13], self.0[14], self.0[15]) 9 | } 10 | } 11 | 12 | impl Mat4 { 13 | /// Build a new (identity) Mat4, which applies no transformations. 14 | pub fn new() -> Self { 15 | Mat4([ 16 | 1.0, 0.0, 0.0, 0.0, 17 | 0.0, 1.0, 0.0, 0.0, 18 | 0.0, 0.0, 1.0, 0.0, 19 | 0.0, 0.0, 0.0, 1.0, 20 | ]) 21 | } 22 | 23 | /// Returns a pointer to the matrix, readable by OpenGL. 24 | pub fn ptr(&self) -> *const f32 { 25 | self.0.as_ptr() 26 | } 27 | 28 | /// Adds `mat` to `self` 29 | pub fn add(&mut self, mat: Mat4) { 30 | self.0.iter_mut().zip(mat.0.iter()).for_each(|(s, m)| *s+=m); 31 | } 32 | 33 | /// Multiplies this Mat4 (`self`) with another one (`mat`), further from the initial vertex position vector, so the resulting transformation will be the chaining of both matrices' transformations: first `self`, then `mat`. 34 | pub fn mult(&mut self, mat: Mat4) { 35 | *self = Mat4([ 36 | mat.0[0] * self.0[0] + mat.0[1] * self.0[4] + mat.0[2] * self.0[8] + mat.0[3] * self.0[12] , mat.0[0] * self.0[1] + mat.0[1] * self.0[5] + mat.0[2] * self.0[9] + mat.0[3] * self.0[13] , mat.0[0] * self.0[2] + mat.0[1] * self.0[6] + mat.0[2] * self.0[10] + mat.0[3] * self.0[14] , mat.0[0] * self.0[3] + mat.0[1] * self.0[7] + mat.0[2] * self.0[11] + mat.0[3] * self.0[15], 37 | mat.0[4] * self.0[0] + mat.0[5] * self.0[4] + mat.0[6] * self.0[8] + mat.0[7] * self.0[12] , mat.0[4] * self.0[1] + mat.0[5] * self.0[5] + mat.0[6] * self.0[9] + mat.0[7] * self.0[13] , mat.0[4] * self.0[2] + mat.0[5] * self.0[6] + mat.0[6] * self.0[10] + mat.0[7] * self.0[14] , mat.0[4] * self.0[3] + mat.0[5] * self.0[7] + mat.0[6] * self.0[11] + mat.0[7] * self.0[15], 38 | mat.0[8] * self.0[0] + mat.0[9] * self.0[4] + mat.0[10] * self.0[8] + mat.0[11] * self.0[12] , mat.0[8] * self.0[1] + mat.0[9] * self.0[5] + mat.0[10] * self.0[9] + mat.0[11] * self.0[13] , mat.0[8] * self.0[2] + mat.0[9] * self.0[6] + mat.0[10] * self.0[10] + mat.0[11] * self.0[14] , mat.0[8] * self.0[3] + mat.0[9] * self.0[7] + mat.0[10] * self.0[11] + mat.0[11] * self.0[15], 39 | mat.0[12] * self.0[0] + mat.0[13] * self.0[4] + mat.0[14] * self.0[8] + mat.0[15] * self.0[12] , mat.0[12] * self.0[1] + mat.0[13] * self.0[5] + mat.0[14] * self.0[9] + mat.0[15] * self.0[13] , mat.0[12] * self.0[2] + mat.0[13] * self.0[6] + mat.0[14] * self.0[10] + mat.0[15] * self.0[14] , mat.0[12] * self.0[3] + mat.0[13] * self.0[7] + mat.0[14] * self.0[11] + mat.0[15] * self.0[15], 40 | ]); 41 | } 42 | 43 | /// Divides self by a float, `scalar`. 44 | pub fn div(&mut self, scalar: f32) { 45 | self.0.iter_mut().for_each(|s| *s/=scalar); 46 | } 47 | 48 | /// Interpolates `self` with `mat` given the advancement (0.0 to 1.0) 49 | pub fn interpolate(&mut self, mat: Mat4, advancement: f32) { 50 | self.0.iter_mut().zip(mat.0.iter()).for_each(|(s, m)| *s = (1.0-advancement) * *s + advancement * m); 51 | } 52 | 53 | /// Add a scale transformation to the Mat4, for each axis. 54 | /// The scale center is (0.0, 0.0, 0.0). 55 | pub fn scale(x_scale: f32, y_scale: f32, z_scale: f32) -> Self { 56 | Mat4([ 57 | x_scale , 0.0 , 0.0 , 0.0 , 58 | 0.0 , y_scale , 0.0 , 0.0 , 59 | 0.0 , 0.0 , z_scale , 0.0 , 60 | 0.0 , 0.0 , 0.0 , 1.0 , 61 | ]) 62 | } 63 | 64 | /// Add a rotation transformation to the Mat4 around the X axis, clockiwse. 65 | /// The rotation center is (0.0, 0.0, 0.0). 66 | pub fn rotate_x(angle: f32) -> Self { 67 | Mat4([ 68 | 1.0 , 0.0 , 0.0 , 0.0 , 69 | 0.0 , angle.cos() , angle.sin() , 0.0 , 70 | 0.0 , -angle.sin(), angle.cos() , 0.0 , 71 | 0.0 , 0.0 , 0.0 , 1.0 , 72 | ]) 73 | } 74 | 75 | /// Add a rotation transformation to the Mat4 around the Y axis, clockiwse. 76 | /// The rotation center is (0.0, 0.0, 0.0). 77 | pub fn rotate_y(angle: f32) -> Self { 78 | Mat4([ 79 | angle.cos() , 0.0 , angle.sin() , 0.0 , 80 | 0.0 , 1.0 , 0.0 , 0.0 , 81 | -angle.sin(), 0.0 , angle.cos() , 0.0 , 82 | 0.0 , 0.0 , 0.0 , 1.0 , 83 | ]) 84 | } 85 | 86 | /// Add a rotation transformation to the Mat4 around the Z axis, clockiwse. 87 | /// The rotation center is (0.0, 0.0, 0.0). 88 | pub fn rotate_z(angle: f32) -> Self { 89 | Mat4([ 90 | angle.cos() , angle.sin() , 0.0 , 0.0 , 91 | -angle.sin(), angle.cos() , 0.0 , 0.0 , 92 | 0.0 , 0.0 , 1.0 , 0.0 , 93 | 0.0 , 0.0 , 0.0 , 1.0 , 94 | ]) 95 | } 96 | 97 | /// Add a translation transformation to the Mat4. 98 | pub fn translate(x_move: f32, y_move: f32, z_move: f32) -> Self { 99 | Mat4([ 100 | 1.0 , 0.0 , 0.0 , x_move , 101 | 0.0 , 1.0 , 0.0 , y_move , 102 | 0.0 , 0.0 , 1.0 , z_move , 103 | 0.0 , 0.0 , 0.0 , 1.0 , 104 | ]) 105 | } 106 | 107 | /// For view matrix. Moves the "camera" to (eye_x, eye_y, eye_z), looking at (target_x, target_y, target_z), with athe (up_x, up_y, up_z) up vector. 108 | pub fn lookat(eye_x: f32, eye_y: f32, eye_z: f32, target_x: f32, target_y: f32, target_z: f32, mut up_x: f32, mut up_y: f32, mut up_z: f32,) -> Self { 109 | // Forward vector 110 | let (mut f_x, mut f_y, mut f_z) = (eye_x-target_x, eye_y-target_y, eye_z-target_z); 111 | let invlen = 1.0 / (f_x*f_x+f_y*f_y+f_z*f_z).sqrt(); 112 | (f_x, f_y, f_z) = (f_x*invlen, f_y*invlen, f_z*invlen); 113 | 114 | // Left vector 115 | let (mut l_x, mut l_y, mut l_z) = (up_y*f_z - up_z*f_y, up_z*f_x - up_x*f_z, up_x*f_y - up_y*f_x); 116 | let invlen = 1.0 / (l_x*l_x+l_y*l_y+l_z*l_z).sqrt(); 117 | (l_x, l_y, l_z) = (l_x*invlen, l_y*invlen, l_z*invlen); 118 | 119 | // Up vector correction 120 | (up_x, up_y, up_z) = (f_y*l_z - f_z*l_y, f_z*l_x - f_x*l_z, f_x*l_y - f_y*l_x); 121 | 122 | 123 | 124 | let mut mat = Self::translate(-eye_x, -eye_y, -eye_z); 125 | mat.mult(Mat4([ 126 | l_x , l_y , l_z , 0.0 , 127 | up_x, up_y, up_z, 0.0 , 128 | f_x , f_y , f_z , 0.0 , 129 | 0.0 , 0.0 , 0.0 , 1.0 , 130 | ])); 131 | mat 132 | } 133 | 134 | /// For projection matrix. Defines an orthographic projection matrix with the given [left-right] - [top-bottom] - [near-far] frustrum. 135 | /// The default Frustrum is set to left-right: [-1.0, 1.0], top-bottom: [-1.0, 1.0], near-far: [-1.0, 1.0] 136 | pub fn project_orthographic(l: f32, r: f32, b: f32, t: f32, n: f32, f: f32) -> Self { 137 | Mat4([ 138 | 2.0 / (r - l) , 0.0 , 0.0 , -(r + l) / (r - l) , 139 | 0.0 , 2.0 / (t - b) , 0.0 , -(t + b) / (t - b) , 140 | 0.0 , 0.0 , -2.0 / (f - n) , -(f + n) / (f - n) , 141 | 0.0 , 0.0 , 0.0 , 1.0 , 142 | ]) 143 | } 144 | 145 | /// For projection matrix. Defines an perspective projection matrix with the given [left-right] - [top-bottom] - [near-far] frustrum. 146 | /// The default Frustrum is set to left-right: [-1.0, 1.0], top-bottom: [-1.0, 1.0], near-far: [-1.0, 1.0] 147 | pub fn project_perspective(l: f32, r: f32, b: f32, t: f32, n: f32, f: f32) -> Self { 148 | Mat4([ 149 | 2.0 * n/(r - l) , 0.0 , (r + l)/(r - l) , 0.0 , 150 | 0.0 , 2.0 * n / (t - b) , (t + b) / (t - b) , 0.0 , 151 | 0.0 , 0.0 , -(f + n) / (f - n) , -(2.0 * f * n)/(f - n) , 152 | 0.0 , 0.0 , -1.0 , 0.0 , 153 | ]) 154 | } 155 | } -------------------------------------------------------------------------------- /vera-core/src/transformer.rs: -------------------------------------------------------------------------------- 1 | use std::f32::consts::PI; 2 | 3 | use vera::{Transformation, Tf, Evolution}; 4 | use crate::Mat4; 5 | 6 | impl Mat4 { 7 | /// Returns the transformation matrix for this transformation, with this advancement. 8 | fn from_t(transformation: Transformation, advancement: f32) -> Self { 9 | match transformation { 10 | Transformation::Scale(x, y, z) => Self::scale(x * advancement + (1.0 - advancement), y * advancement + (1.0 - advancement), z * advancement + (1.0 - advancement)), 11 | Transformation::Translate(x, y, z) => Self::translate(x * advancement, y * advancement, z * advancement), 12 | Transformation::RotateX(angle) => Self::rotate_x(angle * advancement), 13 | Transformation::RotateY(angle) => Self::rotate_y(angle * advancement), 14 | Transformation::RotateZ(angle) => Self::rotate_z(angle * advancement), 15 | 16 | Transformation::Lookat(eye_x, eye_y, eye_z, target_x, target_y, target_z, up_x, up_y, up_z) => Self::lookat(eye_x * advancement, eye_y * advancement, eye_z * advancement, target_x * advancement, target_y * advancement, target_z * advancement, up_x * advancement, up_y * advancement, up_z * advancement), 17 | 18 | // Transformation::Orthographic(l, r, b, t, n, f) => Self::project_orthographic(l * advancement, r * advancement, b * advancement, t * advancement, n * advancement, f * advancement), 19 | Transformation::Perspective(l, r, b, t, n, f) => Self::project_perspective(l * advancement, r * advancement, b * advancement, t * advancement, n * advancement, f * advancement), 20 | #[allow(unreachable_patterns)] 21 | _ => { println!("Transformation not implemented, ignoring."); Mat4::new() }, 22 | } 23 | } 24 | } 25 | 26 | /// Intermediate type between Vertex/Model/View/Projection and buffer-sent Mat4. 27 | /// Contains all transformations in the form of matrices. 28 | pub(crate) struct Transformer { 29 | /// All matrices still needed every frame for `result` calculation. 30 | current: Vec, 31 | 32 | /// The result of the previous matrices multiplication. 33 | /// Modified with current transformations before being sent to the buffer. 34 | result: Mat4, 35 | } 36 | 37 | impl Transformer { 38 | /// Creates a transformer from a vector of transformations. 39 | pub(crate) fn from_t(transformations: Vec) -> Self { 40 | Self { 41 | current: transformations, 42 | 43 | result: Mat4::new(), 44 | } 45 | } 46 | 47 | /// Updates the transformer for view/projection transformations (interpolates every transformation into one), and returns the transformations matrix of the corresponding view/projection for `time`. 48 | pub(crate) fn update_vp(&mut self, time: f32) -> Mat4 { 49 | 50 | // let mut first = true; 51 | // let mut type_of_previous: Option = None; 52 | // 53 | // self.current.retain(|&t| { 54 | // if first { 55 | // if t.end < time { 56 | // self.result.mult(t.mat); 57 | // self.previous.push(t); 58 | // return false; 59 | // } else { 60 | // first = false; 61 | // type_of_previous = Some(t.ty); 62 | // return true; 63 | // } 64 | // } 65 | // 66 | // if type_of_previous == Some(t.ty) { 67 | // if t.end < time { 68 | // self.result.mult(t.mat); 69 | // self.previous.push(t); 70 | // return false; 71 | // } else { 72 | // return true; 73 | // } 74 | // } 75 | // 76 | // type_of_previous = None; 77 | // 78 | // true 79 | // }); 80 | 81 | let mut buffer_matrix = self.result; 82 | self.current.iter().for_each(|tf| { 83 | let adv: f32 = advancement(*tf.read_start(), *tf.read_end(), time, *tf.read_e()); 84 | if adv>0.0 { 85 | buffer_matrix.interpolate(Mat4::from_t(*tf.read_t(), 1.0), adv); 86 | } 87 | }); 88 | buffer_matrix 89 | } 90 | } 91 | 92 | /// Returns the *point of advancement* of `time` on the `start` to `end` journey, with the `e` evolution function. 93 | /// The returned value is between 0.0 and 1.0, where 0.0 is the start and 1.0 is the end. 94 | fn advancement(start: f32, end: f32, time: f32, e: Evolution) -> f32 { 95 | if start>=end { 96 | if time= end { 104 | return 1.0 105 | } 106 | 107 | let init: f32 = (time-start)/(end-start); 108 | match e { 109 | Evolution::Linear => { 110 | init 111 | } 112 | Evolution::FastIn | Evolution::SlowOut => { 113 | (init * PI / 2.0).sin() 114 | } 115 | Evolution::FastOut | Evolution::SlowIn => { 116 | 1.0 - (init * PI / 2.0).cos() 117 | } 118 | Evolution::FastMiddle | Evolution::SlowInOut => { 119 | (((init - 0.5) * PI).sin() + 1.0) / 2.0 120 | } 121 | Evolution::FastInOut | Evolution::SlowMiddle => { 122 | if init < 0.5 { (init * PI).sin() / 2.0 } 123 | else { 0.5 + (1.0 - (init * PI).sin()) / 2.0 } 124 | } 125 | } 126 | } -------------------------------------------------------------------------------- /vera/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "vera" 3 | version = "0.3.0" 4 | # author = "Coddeus" 5 | edition = "2021" 6 | license = "GPL-3.0-only" 7 | description = "Vulkan Engine in Rust for Animation" 8 | documentation = "https://docs.rs/vera" 9 | repository = "https://github.com/Coddeus/vera" 10 | readme = "README.md" 11 | keywords = ["animation", "vulkan", "videos", "graphics", "renderer"] 12 | categories = ["graphics", "multimedia::video", "rendering::engine"] 13 | 14 | [dependencies] 15 | # No vulkano 16 | fastrand = "^2.0" 17 | serde = { version = "1.0.197", features = ["derive"] } 18 | serde_json = "1.0.114" 19 | once_cell = "1.19.0" 20 | 21 | [profile.dev] 22 | opt-level = 0 23 | 24 | [profile.release] 25 | opt-level = 3 -------------------------------------------------------------------------------- /vera/README.md: -------------------------------------------------------------------------------- 1 | # Vera 2 | Defines the Code User Interface sent to [the Vera Core](https://crates.io/crates/vera-core) via its `Input` struct. 3 | 4 | It is defined independently of vulkano, for faster hot-reload. 5 | It is not used directly for the graphics pipeline (e.g. vertex/uniform input), but contains everything for the Vera core to create/animate the shapes once sent. -------------------------------------------------------------------------------- /vera/src/extensions/README.md: -------------------------------------------------------------------------------- 1 | # Extensions 2 | Some shortcuts to avoid boilerplate. There will never be all shortcuts possible. 3 | 4 | ## Modules 5 | Currently available modules: 6 | 7 | ### Model creation 8 | - Shapes 9 | - Text 10 | 11 | Call `.model()` on one of the model creation shortcuts to get the `Model` for it. -------------------------------------------------------------------------------- /vera/src/extensions/mod.rs: -------------------------------------------------------------------------------- 1 | pub mod text; 2 | pub mod shapes; -------------------------------------------------------------------------------- /vera/src/extensions/shapes/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::{Model, ToModel, Vertex}; 2 | 3 | /// A triangle model. 4 | pub struct Triangle { 5 | v1: Vertex, 6 | v2: Vertex, 7 | v3: Vertex, 8 | } 9 | 10 | impl Triangle { 11 | /// A new triangle with these 3 (x, y, z) vertices. 12 | pub fn new(x1: f32, y1: f32, z1: f32, x2: f32, y2: f32, z2: f32, x3: f32, y3: f32, z3: f32) -> Triangle { 13 | Self { 14 | v1: Vertex::new().pos(x1, y1, z1), 15 | v2: Vertex::new().pos(x2, y2, z2), 16 | v3: Vertex::new().pos(x3, y3, z3), 17 | } 18 | } 19 | /// A new triangle from the 3 given vertices. 20 | pub fn from_vertices(v1: Vertex, v2: Vertex, v3: Vertex) -> Triangle { 21 | Self { 22 | v1, 23 | v2, 24 | v3, 25 | } 26 | } 27 | } 28 | 29 | impl ToModel for Triangle { 30 | fn model(self) -> Model { 31 | Model::from_vertices(vec![self.v1, self.v2, self.v3]) 32 | } 33 | } -------------------------------------------------------------------------------- /vera/src/extensions/text/font.rs: -------------------------------------------------------------------------------- 1 | use serde::Deserialize; 2 | use once_cell::sync::Lazy; 3 | 4 | 5 | pub(crate) static CMUNTI: Lazy = Lazy::new(|| 6 | font_from(include_str!("./fonts/cmunti_mtsdf_128_16.json")) 7 | ); 8 | 9 | fn font_from(serd_string: &str) -> FontData { 10 | serde_json::from_str(serd_string).unwrap() 11 | } 12 | 13 | pub(crate) fn char_bounds(c: u8) -> Option<(AtlasBounds, PlaneBounds, f64)> { 14 | let idx = match CMUNTI.glyphs.iter().position(|glyph| glyph.unicode == c as u32) { 15 | Some(idx) => idx, 16 | None => { 17 | return None 18 | } 19 | }; 20 | Some( (CMUNTI.glyphs[idx].atlasBounds.unwrap(), CMUNTI.glyphs[idx].planeBounds.unwrap(), CMUNTI.glyphs[idx].advance) ) 21 | } 22 | pub(crate) fn space_advance() -> Option { 23 | let space_unicode = ' ' as u32; 24 | let space_idx = match CMUNTI.glyphs.iter().position(|glyph| glyph.unicode == space_unicode) { 25 | Some(idx) => idx, 26 | None => { 27 | return None 28 | } 29 | }; 30 | Some(CMUNTI.glyphs[space_idx].advance) 31 | } 32 | 33 | 34 | #[derive(Debug, Deserialize)] 35 | #[allow(unused, non_snake_case)] 36 | pub(crate) struct Atlas { 37 | #[serde(rename = "type")] 38 | atlas_type: String, 39 | distanceRange: u32, 40 | pub(crate) size: u32, 41 | pub(crate) width: u32, 42 | pub(crate) height: u32, 43 | yOrigin: String, 44 | } 45 | 46 | #[derive(Debug, Deserialize, Clone, Copy)] 47 | pub(crate) struct PlaneBounds { 48 | pub(crate) left: f64, 49 | pub(crate) bottom: f64, 50 | pub(crate) right: f64, 51 | pub(crate) top: f64, 52 | } 53 | 54 | #[derive(Debug, Deserialize, Clone, Copy)] 55 | pub(crate) struct AtlasBounds { 56 | pub(crate) left: f64, 57 | pub(crate) bottom: f64, 58 | pub(crate) right: f64, 59 | pub(crate) top: f64, 60 | } 61 | 62 | #[derive(Debug, Deserialize)] 63 | #[allow(unused, non_snake_case)] 64 | struct Metrics { 65 | emSize: f64, 66 | lineHeight: f64, 67 | ascender: f64, 68 | descender: f64, 69 | underlineY: f64, 70 | underlineThickness: f64, 71 | } 72 | 73 | #[derive(Debug, Deserialize, Clone, Copy)] 74 | #[allow(unused, non_snake_case)] 75 | struct Glyph { 76 | unicode: u32, 77 | advance: f64, 78 | planeBounds: Option, 79 | atlasBounds: Option, 80 | } 81 | 82 | #[derive(Debug, Deserialize)] 83 | #[allow(unused)] 84 | pub(crate) struct FontData { 85 | pub(crate) atlas: Atlas, 86 | name: String, 87 | metrics: Metrics, 88 | glyphs: Vec, 89 | } -------------------------------------------------------------------------------- /vera/src/extensions/text/fonts/_cmunti.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Coddeus/vera/e60fe77f32b39540b8bc5b43be026627cf615167/vera/src/extensions/text/fonts/_cmunti.ttf -------------------------------------------------------------------------------- /vera/src/extensions/text/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::{Colorization, Model, ToModel, Vertex}; 2 | 3 | mod font; 4 | 5 | pub struct Text { 6 | string: String, 7 | // The text size 8 | size: f64, 9 | // The offset between characters. 0 for default. 10 | spacing: f64, 11 | spawn_time: f32, 12 | cursor: [f64; 2], 13 | } 14 | 15 | impl Text { 16 | /// Creates a new single-line text 17 | pub fn new(string: String, size: f64, spacing: f64, spawn_time: f32) -> Self { 18 | Self { 19 | string, 20 | size, 21 | spacing, 22 | spawn_time, 23 | cursor: [0.0, 0.0], 24 | } 25 | } 26 | } 27 | 28 | impl ToModel for Text { 29 | fn model(mut self) -> Model { 30 | let width = font::CMUNTI.atlas.width as f32; 31 | let height = font::CMUNTI.atlas.height as f32; 32 | let space_spacing= font::space_advance().unwrap(); 33 | 34 | Model::from_vertices( 35 | self.string.chars().flat_map(|c| { 36 | if c==' ' { 37 | dbg!("Space!"); 38 | self.cursor[0] += space_spacing + self.spacing; 39 | vec![] 40 | } else { 41 | let c2 = c as u32 as u8; 42 | dbg!("Unicode for {}: {}", c, c2); 43 | 44 | let char_bounds: (font::AtlasBounds, font::PlaneBounds, f64) = font::char_bounds(c2).unwrap(); 45 | 46 | 47 | 48 | let vec = vec![ 49 | Vertex::new().a(0.0).recolor(Colorization::ToColor(1.0, 1.0, 1.0, 1.0)).start_c((self.cursor[0] + char_bounds.1.left * self.size) as f32 / 10.0 + self.spawn_time).end_c((self.cursor[0] + char_bounds.1.left * self.size) as f32 / 10.0 + self.spawn_time + 0.5).pos((self.cursor[0] + char_bounds.1.left * self.size) as f32, (self.cursor[1] + char_bounds.1.top * self.size) as f32, 0.1-(self.cursor[0] / 100.0) as f32).tex(1, [char_bounds.0.left as f32 / width, 1.0 - (char_bounds.0.top as f32 / height)]),//[0.0, 1.0] 50 | Vertex::new().a(0.0).recolor(Colorization::ToColor(1.0, 1.0, 1.0, 1.0)).start_c((self.cursor[0] + char_bounds.1.right * self.size) as f32 / 10.0 + self.spawn_time).end_c((self.cursor[0] + char_bounds.1.right * self.size) as f32 / 10.0 + self.spawn_time + 0.5).pos((self.cursor[0] + char_bounds.1.right * self.size) as f32, (self.cursor[1] + char_bounds.1.top * self.size) as f32, 0.1-(self.cursor[0] / 100.0) as f32).tex(1, [char_bounds.0.right as f32 / width, 1.0 - (char_bounds.0.top as f32 / height)]),//[1.0, 1.0] 51 | Vertex::new().a(0.0).recolor(Colorization::ToColor(1.0, 1.0, 1.0, 1.0)).start_c((self.cursor[0] + char_bounds.1.left * self.size) as f32 / 10.0 + self.spawn_time).end_c((self.cursor[0] + char_bounds.1.left * self.size) as f32 / 10.0 + self.spawn_time + 0.5).pos((self.cursor[0] + char_bounds.1.left * self.size) as f32, (self.cursor[1] + char_bounds.1.bottom * self.size) as f32, 0.1-(self.cursor[0] / 100.0) as f32).tex(1, [char_bounds.0.left as f32 / width, 1.0 - (char_bounds.0.bottom as f32 / height)]),//[0.0, 0.0] 52 | 53 | Vertex::new().a(0.0).recolor(Colorization::ToColor(1.0, 1.0, 1.0, 1.0)).start_c((self.cursor[0] + char_bounds.1.right * self.size) as f32 / 10.0 + self.spawn_time).end_c((self.cursor[0] + char_bounds.1.right * self.size) as f32 / 10.0 + self.spawn_time + 0.5).pos((self.cursor[0] + char_bounds.1.right * self.size) as f32, (self.cursor[1] + char_bounds.1.top * self.size) as f32, 0.1-(self.cursor[0] / 100.0) as f32).tex(1, [char_bounds.0.right as f32 / width, 1.0 - (char_bounds.0.top as f32 / height)]),//[1.0, 1.0] 54 | Vertex::new().a(0.0).recolor(Colorization::ToColor(1.0, 1.0, 1.0, 1.0)).start_c((self.cursor[0] + char_bounds.1.left * self.size) as f32 / 10.0 + self.spawn_time).end_c((self.cursor[0] + char_bounds.1.left * self.size) as f32 / 10.0 + self.spawn_time + 0.5).pos((self.cursor[0] + char_bounds.1.left * self.size) as f32, (self.cursor[1] + char_bounds.1.bottom * self.size) as f32, 0.1-(self.cursor[0] / 100.0) as f32).tex(1, [char_bounds.0.left as f32 / width, 1.0 - (char_bounds.0.bottom as f32 / height)]),//[0.0, 0.0] 55 | Vertex::new().a(0.0).recolor(Colorization::ToColor(1.0, 1.0, 1.0, 1.0)).start_c((self.cursor[0] + char_bounds.1.right * self.size) as f32 / 10.0 + self.spawn_time).end_c((self.cursor[0] + char_bounds.1.right * self.size) as f32 / 10.0 + self.spawn_time + 0.5).pos((self.cursor[0] + char_bounds.1.right * self.size) as f32, (self.cursor[1] + char_bounds.1.bottom * self.size) as f32, 0.1-(self.cursor[0] / 100.0) as f32).tex(1, [char_bounds.0.right as f32 / width, 1.0 - (char_bounds.0.bottom as f32 / height)]),//[1.0, 0.0] 56 | ]; 57 | 58 | self.cursor[0] += (char_bounds.2 + self.spacing) * self.size; 59 | 60 | vec 61 | } 62 | }).collect() 63 | ) 64 | } 65 | } -------------------------------------------------------------------------------- /vera/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! Crate root. 2 | //! 3 | //! Contains modifyable global variables (inside unsafe blocks) to choose Default behaviours. These variables start with `D_`. 4 | //! 5 | //! Everything further in this crate is reexported to this level. 6 | //! 7 | //! ## Don't 8 | //! DO NOT modify/read these global variables simutaneously on different threads. 9 | //! Most likely, don't bother creating several threads at all. The Vera core crate will do the performance job. 10 | //! In case you really want multithreading: some function modify/read these variables, but aren't `unsafe` to simplify scripting. Check the docs of the functions you use to know which ones you should be careful with. 11 | 12 | /// Default behaviour: whether or not to choose random colors for each vertex. 13 | /// Overrides `D_VERTEX_COLOR`, but not `D_VERTEX_ALPHA`. 14 | pub static mut D_RANDOM_VERTEX_COLOR: bool = true; 15 | /// Default behaviour: Transformation speed evolution. 16 | pub static mut D_TRANSFORMATION_SPEED_EVOLUTION: Evolution = Evolution::Linear; 17 | /// Default behaviour: Transformation start time. 18 | pub static mut D_TRANSFORMATION_START_TIME: f32 = 0.0; 19 | /// Default behaviour: Transformation end time. 20 | pub static mut D_TRANSFORMATION_END_TIME: f32 = 2.0; 21 | /// Default behaviour: Colorization speed evolution. 22 | pub static mut D_COLORIZATION_SPEED_EVOLUTION: Evolution = Evolution::Linear; 23 | /// Default behaviour: Colorization start time. 24 | pub static mut D_COLORIZATION_START_TIME: f32 = 0.0; 25 | /// Default behaviour: Colorization end time. 26 | pub static mut D_COLORIZATION_END_TIME: f32 = 2.0; 27 | /// Default behaviour: which position to give vertices. 28 | pub static mut D_VERTEX_POSITION: [f32; 3] = [0.0, 0.0, 0.0]; 29 | /// Default behaviour: which color to give vertices. 30 | pub static mut D_VERTEX_COLOR: [f32; 3] = [0.0, 0.0, 0.0]; 31 | /// Default behaviour: What transparency value to give vertices. 32 | pub static mut D_VERTEX_ALPHA: f32 = 1.0; 33 | 34 | /// Default view matrix 35 | pub static mut VIEW: f32 = 0.8; 36 | 37 | /// A vertex, belonging to a model 38 | mod vertex; 39 | pub use vertex::*; 40 | /// A model, something that is drawn 41 | mod model; 42 | pub use model::*; 43 | /// A view, representation of a camera 44 | mod view; 45 | pub use view::*; 46 | /// A projection, defines the viewing frustrum. 47 | mod projection; 48 | pub use projection::*; 49 | /// Transformations for vertices/models, views and projections. 50 | mod transform; 51 | pub use transform::*; 52 | 53 | /// Extensions, to avoid boilerplate in some cases. 54 | mod extensions; 55 | pub use extensions::*; 56 | 57 | /// The input of the Vera core. This is what you send when calling functions like `create()` or `reset()`. 58 | /// It contains everything that will be drawn and updated. 59 | pub struct Input { 60 | /// Metadata for the animation 61 | pub meta: MetaInput, 62 | /// All models, with their transformations. 63 | pub m: Vec, 64 | /// The view, with its transformations 65 | pub v: View, 66 | /// The projection, with its transformations 67 | // /// By default, the visible 3D frustrum corresponds to Transformation::Orthographic(-1.0, 1.0, -1.0, 1.0, 1.0, -1.0) 68 | pub p: Projection, 69 | } 70 | 71 | /// Meta-information about the animation 72 | pub struct MetaInput { 73 | /// The background color. 74 | pub bg: [f32 ; 4], 75 | /// The instant the animation starts. 76 | pub start: f32, 77 | /// The instant the animation end. 78 | pub end: f32, 79 | } 80 | impl Default for MetaInput { 81 | fn default() -> Self { 82 | MetaInput { 83 | bg: [0.3, 0.3, 0.3, 1.0], 84 | start: 0.0, 85 | end: 5.0, 86 | } 87 | } 88 | } -------------------------------------------------------------------------------- /vera/src/model.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | Evolution, Tf, Cl, Transformation, Colorization, Vertex, 3 | D_TRANSFORMATION_SPEED_EVOLUTION, D_TRANSFORMATION_START_TIME, D_TRANSFORMATION_END_TIME, 4 | D_COLORIZATION_SPEED_EVOLUTION, D_COLORIZATION_START_TIME, D_COLORIZATION_END_TIME, 5 | }; 6 | 7 | /// A model (a model is a shape). 8 | /// 1 model = 1 entity. 9 | /// - `models` are the models contained inside of this one. 10 | /// - `vertices` are the vertices of the model (not the submodels), each group of three `Vertex` forming a triangle. Still, you can have the vertices of a same triangle belonging to different models, if you wish. 11 | /// - `t` are the runtime transformations of the model. 12 | #[derive(Clone, Debug)] 13 | pub struct Model { 14 | pub models: Vec, 15 | pub vertices: Vec, 16 | t: Vec, 17 | } 18 | impl Model { 19 | /// Groups `vertices` and `models` in a new model, with empty transformations. 20 | pub fn from_vm(vertices: Vec, models: Vec) -> Self { 21 | Self { 22 | models, 23 | vertices, 24 | t: vec![], 25 | } 26 | } 27 | /// Groups `models` in a new model, with empty transformations. 28 | pub fn from_models(models: Vec) -> Self { 29 | Self { 30 | models, 31 | vertices: vec![], 32 | t: vec![], 33 | } 34 | } 35 | /// Groups `vertices` in a new model, with empty transformations. 36 | /// The number of vertices should (most likely) be a multiple of 3. 37 | pub fn from_vertices(vertices: Vec) -> Self { 38 | Self { 39 | models: vec![], 40 | vertices, 41 | t: vec![], 42 | } 43 | } 44 | 45 | /// Returns all the fields. Consumes `self`. 46 | pub fn own_fields(self) -> (Vec, Vec, Vec) { 47 | ( 48 | self.models, 49 | self.vertices, 50 | self.t, 51 | ) 52 | } 53 | 54 | /// Sets the model's (and submodels') vertices rgb color values. 55 | pub fn rgb(mut self, red: f32, green: f32, blue: f32) -> Self { 56 | self.vertices 57 | .iter_mut() 58 | .for_each(|v| v.set_rgb(red, green, blue)); 59 | self.models 60 | .iter_mut() 61 | .for_each(|m| {m.set_rgb(red, green, blue);}); 62 | self 63 | } 64 | 65 | /// Sets the model's (and submodels') vertices opacity 66 | pub fn alpha(mut self, alpha: f32) -> Self { 67 | self.vertices 68 | .iter_mut() 69 | .for_each(|v| v.set_alpha(alpha)); 70 | self.models 71 | .iter_mut() 72 | .for_each(|m| {m.set_alpha(alpha);}); 73 | self 74 | } 75 | 76 | /// Sets the model's (and submodels') vertices rgb color values. 77 | pub fn set_rgb(&mut self, red: f32, green: f32, blue: f32) { 78 | self.vertices 79 | .iter_mut() 80 | .for_each(|v| v.set_rgb(red, green, blue)); 81 | self.models 82 | .iter_mut() 83 | .for_each(|m| {m.set_rgb(red, green, blue);}); 84 | } 85 | 86 | /// Sets the model's (and submodels') vertices opacity 87 | pub fn set_alpha(&mut self, alpha: f32) { 88 | self.vertices 89 | .iter_mut() 90 | .for_each(|v| v.set_alpha(alpha)); 91 | self.models 92 | .iter_mut() 93 | .for_each(|m| {m.set_alpha(alpha);}); 94 | } 95 | 96 | /// Adds a new transformation to this model with default speed evolution, start time and end time. 97 | /// # Don't 98 | /// DO NOT call this function in multithreaded scenarios, as it calls static mut. See [the crate root](super). 99 | pub fn transform(mut self, transformation: Transformation) -> Self { 100 | self.t.push(Tf { 101 | t: transformation, 102 | e: unsafe { D_TRANSFORMATION_SPEED_EVOLUTION }, 103 | start: unsafe { D_TRANSFORMATION_START_TIME }, 104 | end: unsafe { D_TRANSFORMATION_END_TIME }, 105 | }); 106 | self 107 | } 108 | 109 | pub fn set_t(&mut self, t: Vec) { 110 | self.t = t 111 | } 112 | 113 | /// Adds a new color change to every descendant vertex, with default speed evolution, start time and end time. 114 | /// # Don't 115 | /// DO NOT call this function in multithreaded scenarios, as it calls static mut. See [the crate root](super). 116 | pub fn recolor(mut self, colorization: Colorization) -> Self { 117 | self.vertices.iter_mut().for_each(|v| { v.get_c().push(Cl { 118 | c: colorization, 119 | e: unsafe { D_COLORIZATION_SPEED_EVOLUTION }, 120 | start: unsafe { D_COLORIZATION_START_TIME }, 121 | end: unsafe { D_COLORIZATION_END_TIME }, 122 | })}); 123 | self 124 | } 125 | 126 | /// Modifies the speed evolution of the latest colorization added. 127 | pub fn evolution_c(mut self, e: Evolution) -> Self { 128 | self.vertices.iter_mut().for_each(|v| { v.get_c().last_mut().unwrap().e = e; }); 129 | self 130 | } 131 | 132 | /// Modifies the start time of the latest colorization added. 133 | /// A start after an end will result in the colorization being instantaneous at start. 134 | pub fn start_c(mut self, start: f32) -> Self { 135 | self.vertices.iter_mut().for_each(|v| { v.get_c().last_mut().unwrap().start = start; }); 136 | self 137 | } 138 | 139 | /// Modifies the end time of the latest colorization added. 140 | /// An end before a start will result in the colorization being instantaneous at start. 141 | pub fn end_c(mut self, end: f32) -> Self { 142 | self.vertices.iter_mut().for_each(|v| { v.get_c().last_mut().unwrap().end = end; }); 143 | self 144 | } 145 | 146 | /// Modifies the speed evolution of the latest transformation added. 147 | pub fn evolution_t(mut self, e: Evolution) -> Self { 148 | self.t.last_mut().unwrap().e = e; 149 | self 150 | } 151 | 152 | /// Modifies the start time of the latest transformation added. 153 | /// A start after an end will result in the transformation being instantaneous at start. 154 | pub fn start_t(mut self, start: f32) -> Self { 155 | self.t.last_mut().unwrap().start = start; 156 | self 157 | } 158 | 159 | /// Modifies the end time of the latest transformation added. 160 | /// An end before a start will result in the transformation being instantaneous at start. 161 | pub fn end_t(mut self, end: f32) -> Self { 162 | self.t.last_mut().unwrap().end = end; 163 | self 164 | } 165 | } 166 | 167 | pub trait ToModel { 168 | fn model(self) -> Model; 169 | } -------------------------------------------------------------------------------- /vera/src/projection.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | Evolution, Transformation, Tf, 3 | D_TRANSFORMATION_SPEED_EVOLUTION, D_TRANSFORMATION_START_TIME, D_TRANSFORMATION_END_TIME 4 | }; 5 | 6 | /// A projection (a projection defines the frustrum inside which objects are seen). 7 | /// - `t` are the runtime transformations of the projection. 8 | pub struct Projection { 9 | t: Vec, 10 | } 11 | 12 | impl Projection { 13 | pub fn new() -> Self { 14 | Self { 15 | t: vec![] 16 | } 17 | } 18 | 19 | #[allow(unused_parens)] 20 | pub fn own_fields(self) -> (Vec) { 21 | self.t 22 | } 23 | 24 | /// Adds a new transformation to the overall projection with default speed evolution, start time and end time. 25 | /// # Don't 26 | /// DO NOT call this function in multithreaded scenarios, as it calls static mut. See [the crate root](super). 27 | pub fn transform(mut self, transformation: Transformation) -> Self { 28 | self.t.push(Tf { 29 | t: transformation, 30 | e: unsafe { D_TRANSFORMATION_SPEED_EVOLUTION }, 31 | start: unsafe { D_TRANSFORMATION_START_TIME }, 32 | end: unsafe { D_TRANSFORMATION_END_TIME }, 33 | }); 34 | self 35 | } 36 | 37 | /// Modifies the speed evolution of the latest transformation added. 38 | pub fn evolution_t(mut self, e: Evolution) -> Self { 39 | self.t.last_mut().unwrap().e = e; 40 | self 41 | } 42 | 43 | /// Modifies the start time of the latest transformation added. 44 | /// A start after an end will result in the transformation being instantaneous at start. 45 | pub fn start_t(mut self, start: f32) -> Self { 46 | self.t.last_mut().unwrap().start = start; 47 | self 48 | } 49 | 50 | /// Modifies the end time of the latest transformation added. 51 | /// An end before a start will result in the transformation being instantaneous at start. 52 | pub fn end_t(mut self, end: f32) -> Self { 53 | self.t.last_mut().unwrap().end = end; 54 | self 55 | } 56 | } -------------------------------------------------------------------------------- /vera/src/transform.rs: -------------------------------------------------------------------------------- 1 | /// The evolution of a transformation or colorization. 2 | #[derive(Copy, Clone, Debug)] 3 | pub enum Evolution { 4 | /// Constant speed from start to end. 5 | Linear, 6 | /// Fast at the beginning, slow at the end. 7 | FastIn, 8 | /// Fast at the beginning, slow at the end. 9 | SlowOut, 10 | /// Slow at the beginning, fast at the end. 11 | FastOut, 12 | /// Slow at the beginning, fast at the end. 13 | SlowIn, 14 | /// Slow at ends, fast in middle. 15 | FastMiddle, 16 | /// Slow at ends, fast in middle. 17 | SlowInOut, 18 | /// Fast at ends, slow in middle. 19 | FastInOut, 20 | /// Fast at ends, slow in middle. 21 | SlowMiddle, 22 | } 23 | 24 | // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 25 | 26 | /// Data for the transformation of a single vertex or model. 27 | /// 28 | /// ⚠ The transformations logic order is the order they are added to the vertex or model. Rotation R after translation T will not result in the same thing as T after R (if non-null). 29 | /// It may be different from the order in which they are applied, which depends on the start and end times of each transformation. 30 | /// You can have several transformations happening simultaneously. 31 | #[derive(Clone, Copy, Debug)] 32 | pub struct Tf { 33 | /// The type & value of the transformation. 34 | pub(crate) t: Transformation, 35 | /// The speed evolution of the transformation. 36 | pub(crate) e: Evolution, 37 | /// The start time of the transformation. 38 | pub(crate) start: f32, 39 | /// The end time of the transformation. 40 | pub(crate) end: f32, 41 | } 42 | 43 | impl Tf { 44 | pub fn read_t(&self) -> &Transformation { 45 | &self.t 46 | } 47 | pub fn read_e(&self) -> &Evolution { 48 | &self.e 49 | } 50 | pub fn read_start(&self) -> &f32 { 51 | &self.start 52 | } 53 | pub fn read_end(&self) -> &f32 { 54 | &self.end 55 | } 56 | } 57 | 58 | /// The available transformations. 59 | /// Their doc is prefixed with their general use case: Vertex/Model, View, Projection. 60 | /// Their doc lists the parameters as capital letters in the order they should be given. 61 | #[derive(Clone, Copy, Debug)] 62 | pub enum Transformation { 63 | /// Vertex/Model: A scale operation with the provided X, Y and Z scaling. 64 | Scale(f32, f32, f32), 65 | /// Vertex/Model: A translate operation with the provided X, Y and Z scaling. 66 | Translate(f32, f32, f32), 67 | /// Vertex/Model: A rotate operation around the X axis with the provided counter-clockwise angle, in radians. 68 | RotateX(f32), 69 | /// Vertex/Model: A rotate operation around the Y axis with the provided counter-clockwise angle, in radians. 70 | RotateY(f32), 71 | /// Vertex/Model: A rotate operation around the Z axis with the provided counter-clockwise angle, in radians. 72 | RotateZ(f32), 73 | 74 | /// View: A full definition of the camera with the X, Y and Z eye position (at which point the camera is), the X, Y and Z target position (which point the camera stares at), and an X, Y and Z "up" vector (to determine the camera roll). 75 | Lookat(f32, f32, f32, f32, f32, f32, f32, f32, f32), 76 | // /// View: 77 | // Move(f32, f32, f32), 78 | // /// View: 79 | // Pitch(f32), 80 | // /// View: 81 | // Yaw(f32), 82 | // /// View: 83 | // Roll(f32), 84 | // 85 | // /// Projection: 86 | // Orthographic(f32, f32, f32, f32, f32, f32), 87 | /// Projection: A perspective projection with a near screen with the L left limit, R right limit, B bottom limit and T top limit, at a distance N from the camera and a far screen at a distance F from the camera. 88 | Perspective(f32, f32, f32, f32, f32, f32), 89 | } 90 | 91 | // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 92 | 93 | /// Data for the colorization of a single vertex. 94 | /// 95 | /// ⚠ The colorization logic order is the order they are added to the vertex or model. 96 | /// It may be different from the order in which they are applied, which depends on the start and end times of each transformation. 97 | /// You can have several transformations happening simultaneously. 98 | #[derive(Debug, Clone, Copy)] 99 | pub struct Cl { 100 | /// The type & value of the colorization. 101 | pub(crate) c: Colorization, 102 | /// The speed evolution of the colorization. 103 | pub(crate) e: Evolution, 104 | /// The start time of the colorization. 105 | pub(crate) start: f32, 106 | /// The end time of the colorization. 107 | pub(crate) end: f32, 108 | } 109 | 110 | impl Cl { 111 | pub fn read_c(&self) -> &Colorization { 112 | &self.c 113 | } 114 | pub fn read_e(&self) -> &Evolution { 115 | &self.e 116 | } 117 | pub fn read_start(&self) -> &f32 { 118 | &self.start 119 | } 120 | pub fn read_end(&self) -> &f32 { 121 | &self.end 122 | } 123 | } 124 | 125 | /// The available colorizations. 126 | /// Their doc lists the parameters as capital letters in the order they should be given. 127 | #[derive(Clone, Copy, Debug)] 128 | pub enum Colorization { 129 | /// Changes the current color to this new RGBA color with rgba interpolation. 130 | ToColor(f32, f32, f32, f32), 131 | } -------------------------------------------------------------------------------- /vera/src/vertex.rs: -------------------------------------------------------------------------------- 1 | //! Vertex creation and transformation. 2 | //! This is an intermediate structure later reinterpreted by the Vera core. 3 | 4 | use fastrand::f32; 5 | 6 | use crate::{ 7 | Evolution, Tf, Cl, Transformation, Colorization, 8 | D_TRANSFORMATION_SPEED_EVOLUTION, D_TRANSFORMATION_START_TIME, D_TRANSFORMATION_END_TIME, 9 | D_COLORIZATION_SPEED_EVOLUTION, D_COLORIZATION_START_TIME, D_COLORIZATION_END_TIME, 10 | }; 11 | 12 | /// A vertex with: 13 | /// - its id. Changing it manually has no effect; 14 | /// - the id of the entity it belongs to. Changing it manually has no effect; 15 | /// - a 3D XYZ position; 16 | /// - an RGBA color; 17 | /// - (A Vec of transformations); 18 | /// - (A Vec of colorizations); 19 | /// 20 | /// Vertices enable building Triangles, which enable building all other shapes. 21 | #[derive(Clone, Debug)] 22 | pub struct Vertex { 23 | // Sent to GPU 24 | /// The position of the vertex, XYZW. 25 | position: [f32; 4], 26 | /// The color of the vertex, in RGBA format. 27 | color: [f32; 4], 28 | /// The coordinates of the vertex in the texture. 29 | tex_coord: [f32; 2], 30 | /// The id of the texture this vertex is linked to. For now: 0 if none, 1 if text, Ignored otherwise. 31 | tex_id: u32, 32 | 33 | // Treated in CPU 34 | t: Vec, 35 | c: Vec, 36 | } 37 | impl Vertex { 38 | /// A new default Vertex. Call this method to initialize a vertex, before transforming it. 39 | 40 | /// # Don't 41 | /// DO NOT call this function in multithreaded scenarios, as it calls static mut. See [the crate root](super). 42 | pub fn new() -> Self { 43 | unsafe { 44 | Self { 45 | position: [ 46 | super::D_VERTEX_POSITION[0], 47 | super::D_VERTEX_POSITION[1], 48 | super::D_VERTEX_POSITION[2], 49 | 1.0, 50 | ], 51 | color: if super::D_RANDOM_VERTEX_COLOR { 52 | [f32(), f32(), f32(), super::D_VERTEX_ALPHA] 53 | } else { 54 | [ 55 | super::D_VERTEX_COLOR[0], 56 | super::D_VERTEX_COLOR[1], 57 | super::D_VERTEX_COLOR[2], 58 | super::D_VERTEX_ALPHA, 59 | ] 60 | }, 61 | tex_coord: [0.0, 0.0], 62 | tex_id: 0, 63 | t: vec![], 64 | c: vec![], 65 | } 66 | } 67 | } 68 | 69 | /// Creates a new vertex with the base position and color of `self`. 70 | pub fn duplicate(&self) -> Self{ 71 | Self { 72 | position: self.position, 73 | color: self.color, 74 | tex_coord: [0.0, 0.0], 75 | tex_id: 0, 76 | t: vec![], 77 | c: vec![], 78 | } 79 | } 80 | 81 | /// Returns all the fields. Consumes `self`. 82 | pub fn own_fields(self) -> ([f32; 4], [f32; 4], [f32; 2], u32, Vec, Vec) { 83 | ( 84 | self.position, 85 | self.color, 86 | self.tex_coord, 87 | self.tex_id, 88 | self.t, 89 | self.c, 90 | ) 91 | } 92 | 93 | /// Reads the position data. 94 | pub fn read_position(&self) -> &[f32; 4] { 95 | &self.position 96 | } 97 | /// Reads the color data. 98 | pub fn read_color(&self) -> &[f32; 4] { 99 | &self.color 100 | } 101 | /// Reads the tex_coord data. 102 | pub fn read_tex_coord(&self) -> &[f32; 2] { 103 | &self.tex_coord 104 | } 105 | /// Reads the tex_id data. 106 | pub fn read_tex_id(&self) -> &u32 { 107 | &self.tex_id 108 | } 109 | /// Reads the c data. 110 | pub fn read_c(&self) -> &Vec { 111 | &self.c 112 | } 113 | /// Reads the t data. 114 | pub fn read_tf(&self) -> &Vec { 115 | &self.t 116 | } 117 | 118 | /// Gets a mutable reference to the position data. 119 | pub fn get_position(&mut self) -> &[f32; 4] { 120 | &self.position 121 | } 122 | /// Gets a mutable reference to the color data. 123 | pub fn get_color(&mut self) -> &mut [f32; 4] { 124 | &mut self.color 125 | } 126 | /// Gets a mutable reference to the tex_coord data. 127 | pub fn get_tex_coord(&mut self) -> &mut [f32; 2] { 128 | &mut self.tex_coord 129 | } 130 | /// Gets a mutable reference to the tex_id data. 131 | pub fn get_tex_id(&mut self) -> &mut u32 { 132 | &mut self.tex_id 133 | } 134 | /// Gets a mutable reference to the c data. 135 | pub fn get_c(&mut self) -> &mut Vec { 136 | &mut self.c 137 | } 138 | /// Gets a mutable reference to the t data. 139 | pub fn get_tf(&mut self) -> &mut Vec { 140 | &mut self.t 141 | } 142 | 143 | 144 | /// Modifies the position of the vertex to (x, y, z). 145 | pub fn pos(mut self, x: f32, y: f32, z: f32) -> Self { 146 | self.position = [x, y, z, 1.0]; 147 | self 148 | } 149 | 150 | /// Modifies the red color channel of the vertex color. 151 | pub fn r(mut self, red: f32) -> Self { 152 | self.color[0] = red; 153 | self 154 | } 155 | 156 | /// Modifies the green color channel of the vertex color. 157 | pub fn g(mut self, green: f32) -> Self { 158 | self.color[1] = green; 159 | self 160 | } 161 | 162 | /// Modifies the blue color channel of the vertex color. 163 | pub fn b(mut self, blue: f32) -> Self { 164 | self.color[2] = blue; 165 | self 166 | } 167 | 168 | /// Modifies the alpha color channel of the vertex color. 169 | pub fn a(mut self, alpha: f32) -> Self { 170 | self.color[3] = alpha; 171 | self 172 | } 173 | 174 | /// Modifies the red, green and blue color channels of the vertex color. 175 | pub fn rgb(mut self, red: f32, green: f32, blue: f32) -> Self { 176 | self.color = [red, green, blue, self.color[3]]; 177 | self 178 | } 179 | 180 | /// Modifies the red, green, blue and alpha color channels of the vertex color. 181 | pub fn rgba(mut self, red: f32, green: f32, blue: f32, alpha: f32) -> Self { 182 | self.color = [red, green, blue, alpha]; 183 | self 184 | } 185 | 186 | // /// Sets the position of the vertex and ends the method calls pipe. 187 | // pub(crate) fn set_pos(&mut self, x: f32, y: f32, z: f32) { 188 | // self.position = [x, y, z]; 189 | // } 190 | 191 | /// Sets the color of the vertex and ends the method calls pipe. 192 | pub(crate) fn set_rgb(&mut self, red: f32, green: f32, blue: f32) { 193 | self.color = [red, green, blue, self.color[3]]; 194 | } 195 | 196 | /// Sets the alpha of the vertex and ends the method calls pipe. 197 | pub(crate) fn set_alpha(&mut self, alpha: f32) { 198 | self.color[3] = alpha; 199 | } 200 | 201 | // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 202 | 203 | /// Sets the texture data for this vertex. Crate-visible for now as this is for text only 204 | pub(crate) fn tex(mut self, id: u32, coord: [f32; 2]) -> Self { 205 | self.tex_id = id; 206 | self.tex_coord = coord; 207 | self 208 | } 209 | 210 | // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 211 | 212 | /// Adds a new transformation to this vertex with default speed evolution, start time and end time. 213 | /// # Don't 214 | /// DO NOT call this function in multithreaded scenarios, as it calls static mut. See [the crate root](super). 215 | pub fn transform(mut self, transformation: Transformation) -> Self { 216 | self.t.push(Tf { 217 | t: transformation, 218 | e: unsafe { D_TRANSFORMATION_SPEED_EVOLUTION }, 219 | start: unsafe { D_TRANSFORMATION_START_TIME }, 220 | end: unsafe { D_TRANSFORMATION_END_TIME }, 221 | }); 222 | self 223 | } 224 | 225 | /// Adds a new color change to this vertex with default speed evolution, start time and end time. 226 | /// # Don't 227 | /// DO NOT call this function in multithreaded scenarios, as it calls static mut. See [the crate root](super). 228 | pub fn recolor(mut self, colorization: Colorization) -> Self { 229 | self.c.push(Cl { 230 | c: colorization, 231 | e: unsafe { D_COLORIZATION_SPEED_EVOLUTION }, 232 | start: unsafe { D_COLORIZATION_START_TIME }, 233 | end: unsafe { D_COLORIZATION_END_TIME }, 234 | }); 235 | self 236 | } 237 | 238 | /// Modifies the speed evolution of the latest colorization added. 239 | pub fn evolution_c(mut self, e: Evolution) -> Self { 240 | self.c.last_mut().unwrap().e = e; 241 | self 242 | } 243 | 244 | /// Modifies the start time of the latest colorization added. 245 | /// A start after an end will result in the colorization being instantaneous at start. 246 | pub fn start_c(mut self, start: f32) -> Self { 247 | self.c.last_mut().unwrap().start = start; 248 | self 249 | } 250 | 251 | /// Modifies the end time of the latest colorization added. 252 | /// An end before a start will result in the colorization being instantaneous at start. 253 | pub fn end_c(mut self, end: f32) -> Self { 254 | self.c.last_mut().unwrap().end = end; 255 | self 256 | } 257 | 258 | /// Modifies the speed evolution of the latest transformation added. 259 | pub fn evolution_t(mut self, e: Evolution) -> Self { 260 | self.t.last_mut().unwrap().e = e; 261 | self 262 | } 263 | 264 | /// Modifies the start time of the latest transformation added. 265 | /// A start after an end will result in the transformation being instantaneous at start. 266 | pub fn start_t(mut self, start: f32) -> Self { 267 | self.t.last_mut().unwrap().start = start; 268 | self 269 | } 270 | 271 | /// Modifies the end time of the latest transformation added. 272 | /// An end before a start will result in the transformation being instantaneous at start. 273 | pub fn end_t(mut self, end: f32) -> Self { 274 | self.t.last_mut().unwrap().end = end; 275 | self 276 | } 277 | } 278 | -------------------------------------------------------------------------------- /vera/src/view.rs: -------------------------------------------------------------------------------- 1 | use crate::{ 2 | Evolution, Transformation, Tf, 3 | D_TRANSFORMATION_SPEED_EVOLUTION, D_TRANSFORMATION_START_TIME, D_TRANSFORMATION_END_TIME 4 | }; 5 | 6 | /// A view (a view represents the position, direction and angle of a camera). 7 | /// - `t` are the runtime transformations of the view. 8 | pub struct View { 9 | t: Vec, 10 | } 11 | 12 | impl View { 13 | pub fn new() -> Self { 14 | Self { 15 | t: vec![] 16 | } 17 | } 18 | 19 | #[allow(unused_parens)] 20 | pub fn own_fields(self) -> (Vec) { 21 | self.t 22 | } 23 | 24 | /// Adds a new transformation to the overall view with default speed evolution, start time and end time. 25 | /// # Don't 26 | /// DO NOT call this function in multithreaded scenarios, as it calls static mut. See [the crate root](super). 27 | pub fn transform(mut self, transformation: Transformation) -> Self { 28 | self.t.push(Tf { 29 | t: transformation, 30 | e: unsafe { D_TRANSFORMATION_SPEED_EVOLUTION }, 31 | start: unsafe { D_TRANSFORMATION_START_TIME }, 32 | end: unsafe { D_TRANSFORMATION_END_TIME }, 33 | }); 34 | self 35 | } 36 | 37 | /// Modifies the speed evolution of the latest transformation added. 38 | pub fn evolution_t(mut self, e: Evolution) -> Self { 39 | self.t.last_mut().unwrap().e = e; 40 | self 41 | } 42 | 43 | /// Modifies the start time of the latest transformation added. 44 | /// A start after an end will result in the transformation being instantaneous at start. 45 | pub fn start_t(mut self, start: f32) -> Self { 46 | self.t.last_mut().unwrap().start = start; 47 | self 48 | } 49 | 50 | /// Modifies the end time of the latest transformation added. 51 | /// An end before a start will result in the transformation being instantaneous at start. 52 | pub fn end_t(mut self, end: f32) -> Self { 53 | self.t.last_mut().unwrap().end = end; 54 | self 55 | } 56 | } --------------------------------------------------------------------------------