├── .gitignore ├── LICENSE ├── README.md ├── docs ├── API参考 │ ├── Attachment.md │ ├── GameObject.md │ ├── Gis.md │ ├── Layer.md │ ├── Material.md │ ├── Mesh.md │ ├── Miaokit.md │ ├── Prefab.md │ ├── Scene.md │ ├── Site.md │ ├── Texture2D.md │ ├── Tile.md │ ├── Transform.md │ └── sidebar.md ├── README.md ├── _config.yml ├── index.html ├── sidebar.md ├── 快速上手 │ ├── 5分钟了解MiaokitJS.md │ ├── SVE介绍.md │ ├── sidebar.md │ └── 创建3D图形对象.md └── 素材 │ ├── SVE场景树形图.jpg │ ├── SVE场景管理.jpg │ ├── SVE实施流程.jpg │ ├── SVE工程场景结构.jpg │ ├── SVE新建图层.jpg │ ├── SVE新建工程.jpg │ ├── SVE楼层管理.jpg │ ├── SVE楼层绘制.jpg │ ├── SVE模型打组.jpg │ ├── SVE模型摆放.jpg │ ├── SVE视角管理.jpg │ ├── SVE路径规划.jpg │ └── 整体介绍1.jpg └── web ├── private ├── app │ ├── city.ts │ ├── main.ts │ └── tsconfig.json └── common │ └── util │ ├── camera.ts │ ├── framework.ts │ ├── pipeline.ts │ └── tsconfig.json └── public ├── common ├── miaokit │ ├── Miaokit.wasm │ ├── MiaokitLoader.min.js │ ├── MiaokitWorker.min.js │ └── MiaokitWorker.wasm └── util.js ├── data ├── projects │ ├── config.txt │ └── images │ │ ├── building.png │ │ ├── bus.png │ │ ├── business.png │ │ ├── default.png │ │ ├── logo.png │ │ ├── panor.png │ │ ├── park.png │ │ └── star.jpg └── tools │ ├── Exporter.cs │ └── lzma.exe ├── gis.html └── js └── app.js /.gitignore: -------------------------------------------------------------------------------- 1 | /.git/ 2 | /.vs/ -------------------------------------------------------------------------------- /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 | # MiaokitJS(测试版) 2 | SVE,SVE SDK, 永拓科技,3D可视化,室内导航,GIS,3D GIS,航拍实景模型,倾斜摄影模型,3MX,WebGL,Unity,WASM,Webassembly,浙江永拓信息科技有限公司 3 | 4 | SVE: http://sve.yongtoc.com 5 | 6 | Doc: https://yongtoc.github.io/MiaokitJS/#/ 7 | 8 | Github: https://github.com/YONGTOC/MiaokitJS 9 | 10 | ![图片](./docs/素材/整体介绍1.jpg) 11 | 12 | ## 文件夹结构 13 | * ./doc : 帮助文档文件夹 14 | * ./web : HTML5开发样例工程文件夹 15 | * ./web/private : HTML5开发样例程序源码文件夹 16 | * ./web/public : HTML5开发程序发布文件夹 17 | -------------------------------------------------------------------------------- /docs/API参考/Attachment.md: -------------------------------------------------------------------------------- 1 | # Attachment(实体对象附件) 2 | 3 | ## 概述 4 | 实体对象附件为SVE场景三维对象所绑定的属性数据。 5 | 6 | ## 构造函数 7 | 楼层对象由装载SVE工程数据时自动创建。 8 | 9 | ## 使用样例 10 | ``` 11 | ``` 12 | 13 | ## 属性 14 | * ### .entityType : Int Readonly 15 | 实体类型,值有:Group=1、Collection=2、Component=3、Placeholder=4、Work=5、Layer=6。 16 | * ### .secondType : Int Readonly 17 | 当1==entityType时,值有:Layer=1、Area=2、Group=3。 18 | 19 | 当2==entityType时,值有:ATexture=101、AHoleModel=102、AEdgeModel=103、ETexture=201、EBuildingModel=202、EStoreyModel=203、EFurnitureModel=204、EAssetsModel=205、EPictureModel=206。 20 | 21 | 当3==entityType时,值有:Panel=1、Edge=3、AreaBottom=4、AreaTop=5。 22 | * ### .flag : Int Readonly 23 | 实体属性标志集。 24 | * ### .object3D : GameObject Readonly 25 | 实体所绑定3D图形对象。 26 | * ### .viewState : ViewState Readonly 27 | 实体对象默认观察视角参数。 28 | 29 | ## 方法 30 | 31 | ## 相关对象完整接口参见: 32 | * [GameObject]() -------------------------------------------------------------------------------- /docs/API参考/GameObject.md: -------------------------------------------------------------------------------- 1 | # GameObject(3D图形对象) 2 | 3 | ## 概述 4 | 3D图形对象是用于添加到虚拟三维空间中的对象,通常用于表现一个立体模型。 5 | 6 | ## 构造函数 7 | GameObject() 8 | 9 | 该构造函数构造一个空的3D图形对象。 10 | 11 | ## 使用样例 12 | ``` 13 | let pObject = new MiaokitJS.GameObject(); 14 | for(let pChild of pObject.children){ 15 | pChild.active = false; 16 | } 17 | ``` 18 | 19 | ## 属性 20 | * ### .transform : Transform Readonly 21 | 3D图形对象变换组件。 22 | * ### .mesh : Mesh 23 | 3D图形对象网格组件。 24 | * ### .children : Generator Readonly 25 | 3D图形对象子级列表生成器。 26 | * ### .children.length : Int Readonly 27 | 3D图形对象子级数量。 28 | * ### .parent : GameObject 29 | 3D图形对象父级对象。 30 | * ### .active : Boolean 31 | 3D图形对象激活状态。 32 | * ### .highlight : Boolean 33 | 3D图形对象高亮状态。 34 | * ### .enableCollider : Boolean 35 | 3D图形对象碰撞器启用状态。 36 | * ### .data : any 37 | 3D图形对象绑定自定义数据。 38 | 39 | ## 方法 40 | 41 | ## 相关对象完整接口参见: 42 | * [Transform]() 43 | * [Mesh]() -------------------------------------------------------------------------------- /docs/API参考/Gis.md: -------------------------------------------------------------------------------- 1 | # Gis(GIS控制器对象) 2 | 3 | ## 概述 4 | 全局单例,提供3DGIS交互功能。 5 | 6 | ## 构造函数 7 | 全局单例,通过MiaokitJS.Miaokit.gis访问。 8 | 9 | ## 使用样例 10 | ``` 11 | MiaokitJS.Miaokit.gis.AddSvetile({ 12 | m_nID: 1, 13 | m_nFlags: 0, 14 | m_pUrl: "data/upload/admin/project/20191018/5da9159b2005e.txt", 15 | m_mLngLat: { x: 110.326814, y: 25.248106 }, 16 | m_mSize: { x: 1000.0, y: 1000.0 }, 17 | OnActive: function(pTile, bActive){ 18 | // ... 19 | } 20 | }); 21 | 22 | MiaokitJS.Miaokit.gis.Update(110.326814 * (Math.PI / 180), 25.248106 * (Math.PI / 180), 10000); 23 | ``` 24 | 25 | ## 属性 26 | 27 | ## 方法 28 | * ### .Update(rLng: Float, rLat: Float, nHeight: Float) : void 29 | 刷新地图显示: 30 | 1. rLng : 聚焦经度; 31 | 1. rLat : 聚焦纬度; 32 | 1. nHeight : 观察离地高度; 33 | * ### .AddSvetile(pDesc: any) : Scene 34 | 添加SVE工程到地图中显示。参数说明: 35 | 1. pDesc : SVE工程描述; 36 | 37 | ## 相关对象完整接口参见: 38 | -------------------------------------------------------------------------------- /docs/API参考/Layer.md: -------------------------------------------------------------------------------- 1 | # Layer(SVE楼层对象) 2 | 3 | ## 概述 4 | 楼层对象,一个场景包含多个楼层。 5 | 6 | ## 构造函数 7 | 楼层对象由装载SVE工程数据时自动创建。 8 | 9 | ## 使用样例 10 | ``` 11 | ``` 12 | 13 | ## 属性 14 | * ### .id : String Readonly 15 | 楼层ID。 16 | * ### .object3D : GameObject Readonly 17 | 楼层根节点对象。 18 | * ### .viewState : ViewState Readonly 19 | 楼层预设默认观察视角参数。 20 | * ### .sites : Generator Readonly 21 | 楼层POI列表生成器。 22 | * ### .sites.length : Int Readonly 23 | 楼层POI数量。 24 | 25 | ## 方法 26 | 27 | ## 相关对象完整接口参见: 28 | -------------------------------------------------------------------------------- /docs/API参考/Material.md: -------------------------------------------------------------------------------- 1 | # Material(网格材质) 2 | 3 | ## 概述 4 | 网格材质,用于设置网格的绘制效果。 5 | 6 | ## 构造函数 7 | Material() 8 | 9 | 该构造函数构造一个网格材质对象。 10 | 11 | ## 使用样例 12 | ``` 13 | ``` 14 | 15 | ## 属性 16 | * ### .mainTexture : Texture2D 17 | 网格材质主贴图设置。 18 | 19 | ## 方法 20 | 21 | 22 | ## 相关对象完整接口参见: 23 | * [Texture2D]() -------------------------------------------------------------------------------- /docs/API参考/Mesh.md: -------------------------------------------------------------------------------- 1 | # Mesh(网格组件) 2 | 3 | ## 概述 4 | 网格组件用于表示3D图形对象的几何结构。 5 | 6 | ## 构造函数 7 | Mesh() 8 | 9 | 该构造函数构造一个空的网格组件。 10 | 11 | ## 使用样例 12 | ``` 13 | let aPosition = new Float32Array([...]); 14 | let aNormal = new Float32Array([...]); 15 | let aUV = new Float32Array([...]); 16 | let aIndex = new Int32Array([...]); 17 | 18 | let pMesh = new Mesh(); 19 | pMesh.position = aPosition; 20 | pMesh.normal = aNormal; 21 | pMesh.uv = aUV; 22 | pMesh.triangles = aIndex; 23 | pMesh.Apply(); 24 | ``` 25 | 26 | ## 属性 27 | * ### .position : Float32Array 28 | 网格顶点坐标数组。 29 | * ### .normal : Float32Array 30 | 网格顶点法线数组。 31 | * ### .uv : Float32Array 32 | 网格顶点UV数组。 33 | * ### .triangles : Int32Array 34 | 网格索引数组。 35 | * ### .material : Material 36 | 网格渲染材质。 37 | 38 | ## 方法 39 | * ### .SetVertices(pName: String, pArray: TypeArray) : void 40 | 设置网格顶点数组。参数说明: 41 | 1. pName : 顶点数组类型名称,可选值有 42 | ["position", "normal", "uv", "color", "tangent", "uv2", ..., "uv8"]; 43 | 2. pArray : 顶点数组对象; 44 | * ### .SetIndices(nSubmesh: Int, pArray: TypeArray, nItemSize: Int) : void 45 | 设置网格索引数组。参数说明: 46 | 1. nSubmesh : 子网格索引; 47 | 2. pArray : 索引数组对象; 48 | 3. nItemSize : 索引数组类型,2-Int16Array, 4-Int32Array; 49 | * ### .SetMaterial(nSubmesh: Int, pMaterial: Material) : void 50 | 设置网格材质。参数说明: 51 | 1. nSubmesh : 子网格索引; 52 | 2. pMaterial : 材质对象; 53 | * ### .Apply() : void 54 | 应用当前网格数据应用。 55 | 56 | ## 相关对象完整接口参见: 57 | * [Material]() -------------------------------------------------------------------------------- /docs/API参考/Miaokit.md: -------------------------------------------------------------------------------- 1 | # Miaokit(MiaokitJS核心对象) 2 | 3 | ## 概述 4 | 全局单例,提供若干辅助方法和其他接口入口。 5 | 6 | ## 构造函数 7 | 全局单例,通过MiaokitJS.Miaokit访问。 8 | 9 | ## 使用样例 10 | ``` 11 | let aAnalyze = MiaokitJS.Miaokit.Analyze(60); 12 | console.log(aAnalyze); 13 | ``` 14 | 15 | ## 属性 16 | * ### .camera : GameObject 17 | 主场景摄像机对象。 18 | * ### .gis : Gis 19 | GIS控制器对象。 20 | 21 | ## 方法 22 | * ### .LoadTile(aData: ArrayBuffer) : Tile 23 | 加载SVE工程数据,返回工程瓦片对象。参数说明: 24 | 1. aData : SVE工程数据; 25 | * ### .GetScene(nIndex: Int) : Scene 26 | 获取所有已加载工程中所有场景中的指定场景。参数说明: 27 | 1. nIndex : 场景编号; 28 | * ### .PickEntity(nLayers: Int) : GameObject 29 | 鼠标拾取对象。参数说明: 30 | 1. nLayers : 拾取过滤层标志集; 31 | * ### .Analyze(nFps) : Json[] 32 | 获取MiaokitJS模块剖析数据。参数说明: 33 | 1. nFps : 当前刷新帧率; 34 | 35 | ## 相关对象完整接口参见: 36 | * [Gis]() 37 | * [Tile]() 38 | * [Scene]() 39 | * [GameObject]() -------------------------------------------------------------------------------- /docs/API参考/Prefab.md: -------------------------------------------------------------------------------- 1 | # Prefab(模型预制件) 2 | 3 | ## 概述 4 | 模型预制件,实例化生成模型对象。 5 | 6 | ## 构造函数 7 | LoadPrefab(pUrl: String, pCallback) 8 | 9 | 加载构造一个预制件对象。 10 | 11 | ## 使用样例 12 | ``` 13 | MiaokitJS.LoadPrefab("prefab.assetbundle", function (pPrefab) { 14 | let pObject = pPrefab.Instantiate(); 15 | } 16 | ``` 17 | 18 | ## 属性 19 | 20 | ## 方法 21 | * ### .Instantiate() : GameObject 22 | 实例化预制件生成对象。 23 | 24 | ## 相关对象完整接口参见: 25 | -------------------------------------------------------------------------------- /docs/API参考/Scene.md: -------------------------------------------------------------------------------- 1 | # Scene(SVE场景对象) 2 | 3 | ## 概述 4 | SVE场景对象,一个地图瓦片包含多个场景。 5 | 6 | ## 构造函数 7 | SVE场景对象由装载SVE工程数据时自动创建,并将所有场景添加到全局场景列表中,每个场景被分配一个唯一的场景索引。 8 | 9 | ## 使用样例 10 | ``` 11 | ``` 12 | 13 | ## 属性 14 | * ### .id : String Readonly 15 | 场景ID。 16 | * ### .object3D : GameObject Readonly 17 | 场景根节点对象。 18 | * ### .binding : String Readonly 19 | 场景所绑定楼层对象。 20 | * ### .viewState : ViewState Readonly 21 | 场景预设默认观察视角参数。 22 | * ### .layers : Generator Readonly 23 | 场景楼层列表生成器。 24 | * ### .layers.length : Int Readonly 25 | 场景楼层数量。 26 | 27 | ## 方法 28 | * ### .GetLayer(nIndex: Int) : Layer 29 | 获取场景指定索引楼层对象。参数说明: 30 | 1. nIndex : 楼层编号; 31 | 32 | ## 相关对象完整接口参见: 33 | * [Scene]() -------------------------------------------------------------------------------- /docs/API参考/Site.md: -------------------------------------------------------------------------------- 1 | # Site(POI对象) 2 | 3 | ## 概述 4 | POI对象,标记位置。 5 | 6 | ## 构造函数 7 | POI对象由装载SVE工程数据时自动创建。 8 | 9 | ## 使用样例 10 | ``` 11 | ``` 12 | 13 | ## 属性 14 | * ### .id : String Readonly 15 | POI对象ID。 16 | * ### .scene : Scene Readonly 17 | POI所属场景。 18 | * ### .layer : Layer Readonly 19 | POI所属楼层。 20 | * ### .type : Int Readonly 21 | POI类型。 22 | * ### .number : Int Readonly 23 | POI号码。 24 | * ### .position : Vector3 Readonly 25 | POI坐标。 26 | 27 | ## 方法 28 | 29 | ## 相关对象完整接口参见: 30 | * [Scene]() 31 | * [Layer]() -------------------------------------------------------------------------------- /docs/API参考/Texture2D.md: -------------------------------------------------------------------------------- 1 | # Texture2D(二维贴图对象) 2 | 3 | ## 概述 4 | 通常用于表现网格表面纹理。 5 | 6 | ## 构造函数 7 | Texture2D() 8 | 9 | 该构造函数构造一个空的二维贴图对象。 10 | 11 | ## 使用样例 12 | ``` 13 | let pTexture = new Texture2D(); 14 | pTexture.Load("image.jpg"); 15 | ``` 16 | 17 | ## 属性 18 | 19 | ## 方法 20 | * ### .Load(pUrl: String) : void 21 | 加载网络图片,填充贴图对象。参数说明: 22 | 1. pUrl : 网络图片URL; 23 | * ### .SetImageData(aData: ArrayBuffer) : void 24 | 获取所有已加载工程中所有场景中的指定场景。参数说明: 25 | 1. aData : JPG/PNG图片数据; 26 | 27 | ## 相关对象完整接口参见: 28 | -------------------------------------------------------------------------------- /docs/API参考/Tile.md: -------------------------------------------------------------------------------- 1 | # Tile(地图瓦片/SVE工程对象) 2 | 3 | ## 概述 4 | 地图瓦片/SVE工程对象,一个地图瓦片包含多个场景。 5 | 6 | ## 构造函数 7 | 地图瓦片由装载SVE工程数据时自动创建,并将所有场景添加到全局场景列表中,每个场景被分配一个唯一的场景索引。 8 | 9 | ## 使用样例 10 | ``` 11 | ``` 12 | 13 | ## 属性 14 | * ### .scenes : Generator Readonly 15 | 场景列表生成器。 16 | * ### .scenes.length : Int Readonly 17 | 场景数量。 18 | 19 | ## 方法 20 | 21 | 22 | ## 相关对象完整接口参见: 23 | * [Scene]() -------------------------------------------------------------------------------- /docs/API参考/Transform.md: -------------------------------------------------------------------------------- 1 | # Transform(变换组件) 2 | 3 | ## 概述 4 | 变换组件用于描述一个3D图形对象在虚拟三维空间中的坐标,旋转和大小缩放。使用变换组件我们可以组合搭建出复杂场景,以及创造出各种动态效果。 5 | 6 | ## 构造函数 7 | 变换组件由3D图形对象自动创建,无法调用构造函数构造变换组件。 8 | 9 | ## 使用样例 10 | ``` 11 | let pObject = new MiaokitJS.GameObject(); 12 | let pTransform = pObject.transform; 13 | 14 | pTransform.position = { x:0.0, y:1.0, z:0.0 }; 15 | pTransform.euler = { x:0.0, y:1.0, z:0.0 }; 16 | pTransform.scale = { x:0.0, y:1.0, z:0.0 }; 17 | ``` 18 | 19 | ## 属性 20 | * ### .position : Vector3 21 | 3D图形对象相对世界空间的坐标。 22 | * ### .localPosition : Vector3 23 | 3D图形对象相对父级对象空间的坐标。 24 | * ### .euler : Vector3 25 | 3D图形对象相对世界空间3个轴的旋转欧拉角(角度)。 26 | * ### .localEuler : Vector3 27 | 3D图形对象相对父级对象空间3个轴的旋转欧拉角(角度)。 28 | * ### .rotation : Quaternion 29 | 3D图形对象相对世界空间的旋转四元数。 30 | * ### .localRotation : Quaternion 31 | 3D图形对象相对父级对象空间的旋转四元数。 32 | * ### .scale : Vector3 33 | 3D图形对象相对世界空间3个轴的缩放倍数。 34 | * ### .localScale : Vector3 35 | 3D图形对象相对父级对象空间3个轴的缩放倍数。 36 | * ### .right : Vector3 Readonly 37 | 3D图形对象坐标空间X轴向量在世界空间中的表示。 38 | * ### .up : Vector3 Readonly 39 | 3D图形对象坐标空间Y轴向量在世界空间中的表示。 40 | * ### .forward : Vector3 Readonly 41 | 3D图形对象坐标空间Z轴向量在世界空间中的表示。 42 | 43 | ## 方法 44 | * ### .Rotate(mEuler: Vector3, nRelativeTo: Int) : void 45 | 3D图形对象绕XYZ轴旋转指定角度。参数说明: 46 | 1. mEuler : 绕XYZ轴旋转的角度; 47 | 2. nRelativeTo : 0-旋转相对世界空间的XYZ轴,1-旋转相对对象空间的XYZ轴; 48 | * ### .Rotate2(mAxis: Vector3, nAngle: Float, nRelativeTo: Int) : void 49 | 3D图形对象绕指定轴旋转指定角度。参数说明: 50 | 1. mAxis : 围绕旋转的轴向量; 51 | 2. nAngle : 指定旋转角度; 52 | 2. nRelativeTo : 0-旋转轴在世界空间中表示,1-旋转轴在对象空间中表示; 53 | * ### .Translate(mOffset: Vector3, nRelativeTo: Int) : void 54 | 3D图形对象沿XYZ轴平移指定距离。参数说明: 55 | 1. mOffset : 沿XYZ轴平移的距离; 56 | 2. nRelativeTo : 0-平移相对世界空间的XYZ轴,1-平移相对对象空间的XYZ轴; 57 | 58 | ## 相关对象完整接口参见: 59 | * [GameObject]() 60 | * [Vector3]() 61 | * [Quaternion]() -------------------------------------------------------------------------------- /docs/API参考/sidebar.md: -------------------------------------------------------------------------------- 1 | * [返回上一级](README.md) 2 | * [Miaokit](API参考/Miaokit.md) 3 | * [Gis](API参考/Gis.md) 4 | * [Tile](API参考/Tile.md) 5 | * [Scene](API参考/Scene.md) 6 | * [Layer](API参考/Layer.md) 7 | * [Attachment](API参考/Attachment.md) 8 | * [Site](API参考/Site.md) 9 | * [Prefab](API参考/Prefab.md) 10 | * [GameObject](API参考/GameObject.md) 11 | * [Transform](API参考/Transform.md) 12 | * [Mesh](API参考/Mesh.md) 13 | * [Material](API参考/Material.md) 14 | * [Texture2D](API参考/Texture2D.md) -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # MiaokitJS帮助文档(测试版) 2 | 3 | ## 简介 4 | 【__注意:当前产品尚未可用,预计2019年10月发布上线__】 5 | MiaokitJS是一个轻量级的、移动WEB优先的3D数据可视化框架。框架基于Webassembly和TypeScript开发,具有体量轻、加载速度快、运行效率高等优势。 6 | 框架的“图形渲染”模块参考Unity引擎设计语言设计,并支持Unity引擎扩展,有Unity开发经验的用户将能够很容易上手该框架。 7 | 框架的“场景装载”模块支持装载和访问[SVE](http://sve.yongtoc.com/)所制作打包的三维场景,支持装载倾斜摄影实景模型,并且兼容WMTS标准。可以实现从地球视图到区域、园区、楼宇、楼层、房间、设备等不同级别对象的访问以及进行数据关联绑定。 8 | 框架的“逻辑交互”模块提供了一些基本的三维可视化交互方法,使用户可以基于这些公开的API快速地实现一个可交互的三维可视化产品。 9 | 10 | ### 运行环境 11 | MiaokitJS框架需要运行在支持ES6.0、WebGL2.0、Webassembly特性的浏览器环境中,目前主流的PC和移动端浏览器均已支持。 12 | 13 | ### 项目地址 14 | MiaokitJS框架前端JavaScript代码目前已经开源在[GitHub](https://github.com/YONGTOC/MiaokitJS)上,欢迎为该项目做贡献。 15 | 16 | ### 项目交流 17 | 商务合作:400-808-3066 18 | 技术交流QQ群:333184682 19 | 20 | ## 基本对象 21 | 通过理解以下列出的各个框架所包含的基本对象,我们将对MiaokitJS框架有个基本理解。 22 | 23 | ### 图形渲染 24 | - GameObject:3D图形对象,一个3D场景由多个GameObject组成; 25 | - Mesh:3D网格组件,描述一个3D图形对象的三维空间形态; 26 | - TileMesh:3D地图瓦片网格组件,不同于Mesh,它是基于瓦片数据的,经LOD管理的动态网格; 27 | - Transform:3D变换组件,描述一个3D图形对象的空间位置,旋转和大小缩放,以及不同对象间的层级关系; 28 | - Material:渲染材质,用于控制3D网格渲染效果; 29 | - Texture2D:贴图,用于设置3D网格的表面纹理; 30 | - Camera:摄像机组件,观察三维场景的抽象摄像机,用于将视野范围内的三维场景投影到画布上; 31 | 32 | ### 场景装载 33 | - World:世界,虚拟的三维地球、GIS地图; 34 | - Tile:地图瓦片,[SVE](http://sve.yongtoc.com/)导出的工程数据将被作为一个Tile装载到World中,World可以同时装载多个Tile,为了优化性能和内存开销,需要基于某些机制动态装载卸载Tile; 35 | - Scene:三维场景,一个Tile可以包含多个Scene,通常是一个外景与多个建筑内景; 36 | - Layer:场景图层,一个Scene可以由多个Layer叠加组成。通常,在[SVE](http://sve.yongtoc.com/)中,使用用Layer指代建筑内景中的一个楼层; 37 | - Room:空间区域,一个Layer包含多个Room,通常,在[SVE](http://sve.yongtoc.com/)中,室内用Room指代一个房间、大厅、过道等空间区域; 38 | - Object3D:三维对象。大楼、楼层、门、窗、幕墙、家具、设备、资产等不同级别的三维对象以及不可见对象都用Object3D表示,区别于GameObject,Object3D包含了UUID和资产属性等信息,这些信息一般关联着数据库记录; 39 | - RoadPoint:路径节点,[SVE](http://sve.yongtoc.com/)规划路径中的节点对象,通常用于定位和导航规划; 40 | - Site:位置标记。[SVE](http://sve.yongtoc.com/)规划路径中的位置标记对象,通常用于定位和导航规划; 41 | 42 | ### 逻辑交互 43 | - MiaokitLoader:MiaokitJS框架装载器,使用MiaokitJS框架的唯一入口,每个框架实例在其独立的闭包环境中运行,即,可以在页面中创建多个框架实例显示多个可视化界面; 44 | - SVE:[SVE](http://sve.yongtoc.com/)场景装载器,用于动态装载卸载瓦片数据,访问当前已装载瓦片的不同层级对象数据,控制不同层级对象的表现和行为; 45 | - CameraCtrl:MiaokitJS框架提供的默认摄像机控制器,用于在三维场景中漫游查看; 46 | - Navigator:导航路径生成器,用于搜索两个位置点间的最优路径; 47 | - Navigation:MiaokitJS框架提供的默认导航控制器,提供包括路径绘制、模拟导航、实时导航、定位跟踪、语言播报、摄像机跟随等功能; 48 | - 矢量数学库:Vector2、Vector3、Vector4等矢量数据的表示和计算; 49 | - 辅助工具:包含计时器、数据异步加载器、调试跟踪器等辅助工具; -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-leap-day -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /docs/sidebar.md: -------------------------------------------------------------------------------- 1 | * [MiaokitJS 2020.0](README.md) 2 | * [快速上手](快速上手/5分钟了解MiaokitJS.md) 3 | * [API参考](API参考/Miaokit.md) 4 | * [FAQ](FAQ/) -------------------------------------------------------------------------------- /docs/快速上手/5分钟了解MiaokitJS.md: -------------------------------------------------------------------------------- 1 | # 5分钟了解MiaokitJS 2 | 3 | ## MiaokitJS安装 4 | 我们可以在SVE官网直接[下载](http://sve.yongtoc.com/)库脚本文件,并通过<script>标签引入。下载的库文件压缩包包含一下文件: 5 | 1. Miaokit.wasm - 核心模块二进制代码文件; 6 | 2. MiaokitLoader.js - 核心模块装载器脚本; 7 | 3. Miaokit.js - 接口封装和交互逻辑脚本; 8 | 4. MiaokitU3D - Unity引擎扩展文件夹; 9 | 5. MiaokitU3D/Build/UnityLoader.js - Unity引擎扩展Unity引擎装载器脚本; 10 | 11 | ## 基本程序框架 12 | 本帮助文档中所有样例程序中的框架实例名称都命名为MiaokitJS,这也是我们建议的命名,实例MiaokitJS是框架其它所有类和对象的唯一访问入口。 13 | 每个框架实例在其独立的闭包环境中运行,我们可以在页面中创建多个框架实例。 14 | ``` 15 | 16 | 17 | MiaokitJS 18 | 19 | 20 | 21 | 27 | 28 | 29 |
30 | 31 | 37 | 38 | 39 | ``` 40 | [在线运行]() 41 | 42 | ## 运行调试 43 | 我们需要将程序部署到WEB服务器中,通过浏览器访问,您也可以直访问我们的[在线编辑器]()进行快速体验。在部署完成并浏览器成功访问后,我们可以按F12键,打开浏览器调试控制台,控制台会打印出框架的一些运行信息。 44 | 上面的基本程序框架样例运行后会打印出如下一些信息(数值为时间戳): 45 | > Track: 3 Preload 46 | > Track: 15 LoadEngine 47 | > Initialize engine version: 2019.1.0f2 (292b93d75a2c) 48 | > Creating WebGL 2.0 context. 49 | > Track: 1855 LoadEngine End 50 | > Track: 1855 LoadMiaokit 51 | > Track: 2435 LoadMiaokit End 52 | 53 | ## 接口访问 54 | 在框架实例启动完成后,我们可以通过以下方法访问框架提供的接口: 55 | ``` 56 | 65 | ``` 66 | 以上代码创建一个3D图形对象并设置它的坐标位置,MiaokitJS实例的完整接口参见[MiaokitJS API参考]()。 67 | 68 | ## 框架配置 69 | 框架预加载前,我们可以对框架进行一些配置。 70 | ``` 71 | 104 | ``` 105 | -------------------------------------------------------------------------------- /docs/快速上手/SVE介绍.md: -------------------------------------------------------------------------------- 1 | # SVE介绍 2 | 3 | ## 复杂三维场景构建 4 | 在[创建3D图形对象]()一章中我们已经介绍了如何用代码创建一个简单的3D图形对象。但是一般系统应用中3D可视化部分会使用到包含大量3D图形对象的复杂场景,这些对象又具有不同深度的层级结构,并且是实时动态变化的。比如门禁开关,制造机器人的机械臂运动状态这些又与现场情况实时连接,在这种情形下,我们用代码来一个个定义3D图形对象是不现实的。 5 | 首先是复杂的几何结构,我们不会继续使用代码来一个个定义顶点坐标,而是使用现在市面上成熟的建模工具来建模,比如3DS MAX和MAYA,在建模完成后,通过我们的[导入工具]()转换成MiaokitJS框架所使用的资源格式,并保存到资源库中。一般我们仅用建模工具设计门、窗、家具家电、设备、景观等独立的对象。 6 | 在设计出一个个独立的模型后,我们需要将它们搭建成一个复杂场景,确认它们所在层级、坐标位置、和唯一ID,然后我们在程序中才能与这些独立对象做数据关联和交互绑定,并且能单独地控制这些对象的各种状态。因此,SVE就是我们这里所必须的场景搭建工具。 7 | 8 | ## 基础概念 9 | SVE即是一个三维场景搭建工具,也是一个三维地图瓦片制作工具。我们可以创建多个SVE工程,每个工程表示一个地图瓦片,搭建完成进行导出,然后在MiaokitJS框架中装载,就可以在前端呈现出我们所搭建的三维场景。 10 | 一个SVE工程(三维地图瓦片)可以包含多个三维场景,通常是一个室外场景和多个室内场景。室内场景分多个楼层,多个房间。然后我们可以在这里场景中摆放数量不定的3D图形对象,以此美化和完善我们的可视化场景。 11 | ![图片](../素材/SVE工程场景结构.jpg) 12 | 13 | ## SVE操作简介 14 | * 新建工程:进入SVE新建工程后,编辑器会提示默认新建一个空白场景,此时点击确认; 15 | ![图片](../素材/SVE新建工程.jpg) 16 | * 新建图层:每个新建场景,编辑器会自动创建一个默认图层,在图层之上进行编辑,您也可以添加和插入新图层; 17 | ![图片](../素材/SVE新建图层.jpg) 18 | * 编辑模式:楼层绘制、模型摆放、路径规划; 19 | 楼层绘制:编辑一个楼层的建筑格局,包括墙面、地板、天花板绘制生成,门窗摆放、地砖墙纸设置; 20 | ![图片](../素材/SVE楼层绘制.jpg) 21 | 模型摆放:将设计师制作好的三维模型摆放到场景中,增加场景的细节或者是放置需要监控的重要资产; 22 | ![图片](../素材/SVE模型摆放.jpg) 23 | 模型摆放可以层层打组,从而构建场景树形层级结构; 24 | ![图片](../素材/SVE模型打组.jpg) 25 | 路径规划:编辑规划寻路路径,编辑POI位置点,用于位置查找和导航; 26 | ![图片](../素材/SVE路径规划.jpg) 27 | * 楼层管理:可以新建、插入、复制、命名楼层; 28 | ![图片](../素材/SVE楼层管理.jpg) 29 | * 场景管理:目前,编辑器除了默认场景,其它追加的场景都与一栋楼宇进行绑定关联(类似于传送门)。楼宇内场景亦可以插入新的楼宇(场景)。因此,场景会以树形结构组织,默认场景是根节点; 30 | ![图片](../素材/SVE场景管理.jpg) 31 | * 视角管理:在树形结构的每个节点都可以设置单独的摄像机观察视角; 32 | ![图片](../素材/SVE视角管理.jpg) 33 | * 工程对象树形图管理:编辑器编辑的项目数据会以树形结构组织,便于操作; 34 | ![图片](../素材/SVE场景树形图.jpg) 35 | * 项目实施流程: 36 | ![图片](../素材/SVE实施流程.jpg) 37 | 详细介绍和使用教程请访问[SVE官网](http://sve.yongtoc.com/) 38 | -------------------------------------------------------------------------------- /docs/快速上手/sidebar.md: -------------------------------------------------------------------------------- 1 | * [返回上一级](README.md) 2 | * [5分钟了解MiaokitJS](快速上手/5分钟了解MiaokitJS.md) 3 | * [创建3D图形对象](快速上手/创建3D图形对象.md) 4 | * [SVE介绍](快速上手/SVE介绍.md) -------------------------------------------------------------------------------- /docs/快速上手/创建3D图形对象.md: -------------------------------------------------------------------------------- 1 | # 创建3D图形对象 2 | 3 | ## 计算机图形学 4 | 这里我们需要对计算机图形学作个基本了解。计算机图形学核心目标可以分解为三个基本任务:表示、交互、绘制,MiaokitJS提供了对应的3组能力来完成这3个任务,并隐藏了底层复杂的操作。 5 | 6 | ### 3D形态表示 7 | 用程序语言和数据表示一个几何形态,描述点、线、面、体等对象。我们使用一个三维向量MiaokitJS.Vector3在笛卡尔坐标系中定义一个空间点,2点表示1条线,3点表示一个三角形。 8 | 在JavaScript中使用Float32Array描述几何所有顶点的坐标,Float32Array.length / 3为顶点个数。 9 | 为了使几何形态绘制更加具有真实感,需要添加光照,进行几何形体的表面纹理映射等操作,这需要我们定义更多的几何属性数据,比如顶点的法线数据,顶点的纹理采样UV数据等,方法与定义坐标类似。 10 | 定义了顶点的属性数据,我们还要描述几何形体的面,三维空间中的形体就是用一组的三角形面表示,因此,程序渲染出来的几何体是“空心”的。使用索引数组(Int32Array)表示一组三角形面,索引是对顶点属性的索引,3个索引表示3个顶点顺时针连接形成一个三角形面,Int32Array.length / 3为三角形面个数。 11 | 例如:一个最基本的立方体,由8个顶点坐标,36个索引表示。 12 | 13 | ### 3D状态交互 14 | 上面我们介绍了3D形态的表示方法,表示出来的几何体是静止不动的,但是我们世界中,是处于不停的运动和变化的。因此,我们需要控制几何体的放置位置,控制它的旋转、缩放、控制各个关节的状态以及控制观察者“眼睛”的观察位置和观察角度。这样我们的虚拟世界就活动起来了。 15 | 16 | ### 3D几何绘制 17 | 我们有方法表示一个3D世界,并让它运动了起来,然后,我们需要将它呈现到浏览器的2D画布上,同时需要使成像效果更加接近真实。当下主流的图形绘制方法是基于光栅化的,这部分细节不在此过多描述。 18 | 为了增加真实感,我们需要设置几何的光照材质,设置表面贴图,添加光照等参数。 19 | 20 | ## 创建3D图形对象 21 | 22 | ### 定义顶点坐标数组 23 | ``` 24 | let GetPosition = function() { 25 | return new Float32Array([ 26 | // 顶部2个三角形的顶点坐标 27 | -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 28 | -1.0, -1.0, -1.0, 1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 29 | // 顶部2个三角形的顶点坐标 30 | -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 31 | -1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 32 | // 正面2个三角形的顶点坐标 33 | -1.0, -1.0, -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 34 | -1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, -1.0, 35 | // 右侧2个三角形的顶点坐标 36 | 1.0, -1.0, -1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 1.0, 37 | 1.0, -1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 38 | // 背面2个三角形的顶点坐标 39 | 1.0, -1.0, 1.0, 1.0, 1.0, 1.0, -1.0, 1.0, 1.0, 40 | 1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, -1.0, 1.0, 41 | // 左侧2个三角形的顶点坐标 42 | -1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 43 | -1.0, -1.0, 1.0, -1.0, 1.0, -1.0, -1.0, -1.0, -1.0, 44 | ]); 45 | } 46 | ``` 47 | 48 | ### 定义顶点法线数组 49 | ``` 50 | let GetNormal = function() { 51 | return new Float32Array([ 52 | // 顶部2个三角形的顶点法线 53 | 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 54 | 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 55 | // 顶部2个三角形的顶点法线 56 | 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 57 | 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 58 | // 正面2个三角形的顶点法线 59 | 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 60 | 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 61 | // 右侧2个三角形的顶点法线 62 | 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 63 | 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 64 | // 背面2个三角形的顶点法线 65 | 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 66 | 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 1.0, 67 | // 左侧2个三角形的顶点法线 68 | -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 69 | -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, -1.0, 0.0, 0.0, 70 | ]); 71 | } 72 | ``` 73 | 74 | ### 定义顶点UV数组 75 | ``` 76 | let GetUV = function() { 77 | return new Float32Array([ 78 | // 顶部2个三角形的顶点UV 79 | 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 80 | 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 81 | // 顶部2个三角形的顶点UV 82 | 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 83 | 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 84 | // 正面2个三角形的顶点UV 85 | 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 86 | 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 87 | // 右侧2个三角形的顶点UV 88 | 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 89 | 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 90 | // 背面2个三角形的顶点UV 91 | 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 92 | 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 93 | // 左侧2个三角形的顶点UV 94 | 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 95 | 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 96 | ]); 97 | } 98 | ``` 99 | 100 | ### 定义三角形索引数组 101 | ``` 102 | let GetIndex = function() { 103 | let aIndex = new Int32Array(36); 104 | 105 | for (let i = 0; i < 36; i++) { 106 | aIndex[i] = i; 107 | } 108 | 109 | return aIndex; 110 | } 111 | ``` 112 | 113 | ### 创建网格表面贴图 114 | ``` 115 | let CreateTexture = function() { 116 | let pTexture = MiaokitJS.CreateTexture2D(); 117 | pTexture.LoadImage("texture.png"); 118 | 119 | return pTexture; 120 | } 121 | ``` 122 | 123 | ### 创建网格光照材质 124 | ``` 125 | let CreateMaterial = function() { 126 | let pMaterial = MiaokitJS.CreateMaterial(); 127 | pMaterial.mainTexture = CreateTexture(); 128 | 129 | return pMaterial; 130 | } 131 | ``` 132 | 133 | ### 创建网格组件 134 | ``` 135 | let CreateMesh = function() { 136 | let pMesh = MiaokitJS.CreateMesh(); 137 | pMesh.position = GetPosition(); 138 | pMesh.normal = GetNormal(); 139 | pMesh.uv = GetUV(); 140 | pMesh.SetIndices(0, GetIndex()); 141 | pMesh.SetMaterial(0, CreateMaterial()); 142 | pMesh.Apply(); 143 | 144 | return pMesh; 145 | } 146 | ``` 147 | 148 | ### 创建3D图形对象 149 | ``` 150 | let CreateGameObject = function() { 151 | let pObject = MiaokitJS.CreateGameObject(); 152 | pObject.transform.position = new MiaokitJS.Vector3(0.0, 1.0, 0.0); 153 | pObject.mesh = CreateMesh(); 154 | 155 | return pObject; 156 | } 157 | ``` 158 | [在线运行完整样例]() 159 | 160 | ### 相关对象完整接口参见: 161 | * [Texture2D]() 162 | * [Material]() 163 | * [Mesh]() 164 | * [Transform]() 165 | * [GameObject]() -------------------------------------------------------------------------------- /docs/素材/SVE场景树形图.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE场景树形图.jpg -------------------------------------------------------------------------------- /docs/素材/SVE场景管理.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE场景管理.jpg -------------------------------------------------------------------------------- /docs/素材/SVE实施流程.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE实施流程.jpg -------------------------------------------------------------------------------- /docs/素材/SVE工程场景结构.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE工程场景结构.jpg -------------------------------------------------------------------------------- /docs/素材/SVE新建图层.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE新建图层.jpg -------------------------------------------------------------------------------- /docs/素材/SVE新建工程.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE新建工程.jpg -------------------------------------------------------------------------------- /docs/素材/SVE楼层管理.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE楼层管理.jpg -------------------------------------------------------------------------------- /docs/素材/SVE楼层绘制.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE楼层绘制.jpg -------------------------------------------------------------------------------- /docs/素材/SVE模型打组.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE模型打组.jpg -------------------------------------------------------------------------------- /docs/素材/SVE模型摆放.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE模型摆放.jpg -------------------------------------------------------------------------------- /docs/素材/SVE视角管理.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE视角管理.jpg -------------------------------------------------------------------------------- /docs/素材/SVE路径规划.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/SVE路径规划.jpg -------------------------------------------------------------------------------- /docs/素材/整体介绍1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/docs/素材/整体介绍1.jpg -------------------------------------------------------------------------------- /web/private/app/city.ts: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/private/app/city.ts -------------------------------------------------------------------------------- /web/private/app/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "module": "system", 5 | "outDir": "../../public/js", 6 | "outFile": "../../public/js/app.js", 7 | "noImplicitAny": false, 8 | "noEmitOnError": true, 9 | "removeComments": true, 10 | "sourceMap": false, 11 | "target": "es6" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /web/private/common/util/camera.ts: -------------------------------------------------------------------------------- 1 |  2 | enum CTRL_MODE { 3 | /// 无效模式。 4 | INVALID = 0, 5 | /// 遥感模式:远地模式,始终垂直地表,可以设置目标经纬度和镜头距地高度。 6 | REMOTE = 1, 7 | /// 鹰眼模式:近地模式,距地高度20000米一下,可以设置目标经纬度和镜头距目标距离,可以设置镜头偏航角和俯仰角。 8 | EAGLE = 2, 9 | /// 全景模式:近地模式,锁定目标,固定场景中心经纬度,可以设置目标坐标,可以设置观察设备距目标距离、偏航角、俯仰角。 10 | PANORAMA = 3, 11 | /// 漫游模式:地表模式,无目标,可以移动自身位置,可设置偏航角、俯仰角。 12 | WANDER = 4, 13 | } 14 | 15 | enum VIEW_MODE { 16 | /// 无效模式。 17 | INVALID = 1, 18 | /// 2D视图。 19 | _2D = 2, 20 | /// 3D视图。 21 | _3D = 3 22 | } 23 | 24 | 25 | class RemoteParam { 26 | /// 目标经度坐标。 27 | public m_nLng: number = 0.0; 28 | /// 目标纬度坐标。 29 | public m_nLat: number = 0.0; 30 | /// 镜头距地表高度。 31 | public m_nHeight: number = 0.0; 32 | } 33 | 34 | class EagleParam { 35 | /// 目标经度坐标。 36 | public m_nLng: number = 0.0; 37 | /// 目标纬度坐标。 38 | public m_nLat: number = 0.0; 39 | /// 镜头距目标距离。 40 | public m_nDistance: number = 0.0; 41 | 42 | /// 镜头对目标的俯角。 43 | public m_nPitch: number = 0.0; 44 | /// 镜头对目标的偏航角。 45 | public m_nYaw: number = 0.0; 46 | } 47 | 48 | class PanoramaParam { 49 | /// 场景中心经度坐标。 50 | public m_nLng: number = 0.0; 51 | /// 场景中心纬度坐标。 52 | public m_nLat: number = 0.0; 53 | 54 | /// 目标坐标。 55 | public m_mTarget: any = { x: 0.0, y: 0.0, z: 0.0 }; 56 | /// 镜头距目标距离。 57 | public m_nDistance: number = 0.0; 58 | /// 镜头对目标的俯角。 59 | public m_nPitch: number = 0.0; 60 | /// 镜头对目标的偏航角。 61 | public m_nYaw: number = 0.0; 62 | } 63 | 64 | class WanderParam { 65 | /// 场景中心经度坐标。 66 | public m_nLng: number = 0.0; 67 | /// 场景中心纬度坐标。 68 | public m_nLat: number = 0.0; 69 | 70 | /// 角色坐标。 71 | public m_mPosition: any = { x: 0.0, y: 0.0, z: 0.0 }; 72 | /// 角色视线俯角。 73 | public m_nPitch: number = 0.0; 74 | /// 角色视线偏航角。 75 | public m_nYaw: number = 0.0; 76 | } 77 | 78 | 79 | class CameraCtrl { 80 | /// 构造函数。 81 | public constructor(pCamera) { 82 | this.m_pCamera = pCamera; 83 | this.m_pTransform = this.m_pCamera.transform; 84 | } 85 | 86 | /// 立即设置新的摄像机控制模式。 87 | public Jump(eMode: CTRL_MODE, pParam: any): void { 88 | this.m_eCtrlMode = eMode; 89 | 90 | if (CTRL_MODE.REMOTE === eMode) { 91 | this.m_nLng = pParam.m_nLng; 92 | this.m_nLat = pParam.m_nLat; 93 | this.m_nDistance = pParam.m_nHeight; 94 | this.m_nPitch = 90.0; 95 | this.m_nYaw = 0.0; 96 | this.m_mTarget = { x: 0.0, y: 0.0, z: 0.0 }; 97 | } 98 | else if (CTRL_MODE.EAGLE === eMode) { 99 | this.m_nLng = pParam.m_nLng; 100 | this.m_nLat = pParam.m_nLat; 101 | this.m_nDistance = pParam.m_nDistance; 102 | this.m_nPitch = pParam.m_nPitch; 103 | this.m_nYaw = pParam.m_nYaw; 104 | this.m_mTarget = { x: 0.0, y: 0.0, z: 0.0 }; 105 | } 106 | else if (CTRL_MODE.PANORAMA === eMode) { 107 | this.m_nLng = pParam.m_nLng; 108 | this.m_nLat = pParam.m_nLat; 109 | this.m_nDistance = pParam.m_nDistance; 110 | this.m_nPitch = pParam.m_nPitch; 111 | this.m_nYaw = pParam.m_nYaw; 112 | this.m_mTarget = { x: pParam.m_mTarget.x, y: pParam.m_mTarget.y, z: pParam.m_mTarget.z }; 113 | } 114 | else if (CTRL_MODE.WANDER === eMode) { 115 | this.m_nLng = pParam.m_nLng; 116 | this.m_nLat = pParam.m_nLat; 117 | this.m_nDistance = 0.0; 118 | this.m_nPitch = pParam.m_nPitch; 119 | this.m_nYaw = pParam.m_nYaw; 120 | this.m_mTarget = { x: pParam.m_mPosition.x, y: pParam.m_mPosition.y, z: pParam.m_mPosition.z }; 121 | } 122 | } 123 | 124 | /// 移动摄像机。 125 | public Move(nOffsetX, nOffsetY, nWidth, nHeight): void { 126 | if (!this.m_nEnabled) { 127 | return; 128 | } 129 | 130 | if (CTRL_MODE.REMOTE === this.ctrlMode || CTRL_MODE.EAGLE === this.ctrlMode) { 131 | // 60度视角下,距地表距离为地球半径时视线刚好能切过地球,并且垂直可视角度范围为120度 132 | let nDistance = this.distance; 133 | let nLng = this.lng; 134 | let nLat = this.lat; 135 | 136 | if (nDistance > 6378137.0) { 137 | nDistance = 6378137.0; 138 | } 139 | 140 | if (nDistance < 0.0) { 141 | nDistance = 0.0; 142 | } 143 | 144 | // 可见弧度角性变化 145 | let nAngle = nDistance / 6378137.0 * 120.0; 146 | let offsetLng = nOffsetX / nWidth * (nAngle * nWidth / nHeight); 147 | let offsetLat = nOffsetY / nHeight * nAngle; 148 | 149 | offsetLng *= 0.6; 150 | offsetLat *= 0.6; 151 | 152 | let rYaw = (this.yaw / 180.0) * Math.PI; 153 | nLng += offsetLng * Math.cos(rYaw); 154 | nLat -= offsetLng * Math.sin(rYaw); 155 | nLat += offsetLat * Math.cos(rYaw); 156 | nLng += offsetLat * Math.sin(rYaw); 157 | 158 | this.lng = nLng; 159 | this.lat = nLat; 160 | } 161 | else if (CTRL_MODE.PANORAMA === this.ctrlMode) { 162 | let nViewHeight = 1.0 * this.distance; 163 | let nFactor = nViewHeight / nHeight; 164 | 165 | nOffsetX *= nFactor; 166 | nOffsetY *= nFactor; 167 | 168 | let mTarget = this.target; 169 | if (2 === this.m_nViewMode) { 170 | mTarget.x += nOffsetX; 171 | mTarget.z += nOffsetY; 172 | } 173 | else { 174 | let rYaw = (this.yaw / 180.0) * Math.PI; 175 | mTarget.x += nOffsetX * Math.cos(rYaw); 176 | mTarget.z -= nOffsetX * Math.sin(rYaw); 177 | mTarget.z += nOffsetY * Math.cos(rYaw); 178 | mTarget.x += nOffsetY * Math.sin(rYaw); 179 | } 180 | 181 | this.target = mTarget; 182 | } 183 | } 184 | 185 | /// 旋转视野。 186 | public Rotate(nOffsetX, nOffsetY, nWidth, nHeight): void { 187 | if (!this.m_nEnabled) { 188 | return; 189 | } 190 | 191 | if (2 === this.m_nViewMode) { 192 | return; 193 | } 194 | 195 | if (CTRL_MODE.REMOTE !== this.ctrlMode) { 196 | let nPitch = this.pitch; 197 | let nYaw = this.yaw; 198 | 199 | nYaw += nOffsetX / nWidth * 180; 200 | nPitch += nOffsetY / nHeight * 90.0; 201 | 202 | if (5.0 > nPitch) { 203 | nPitch = 5.0; 204 | } 205 | 206 | if (90.0 < nPitch) { 207 | nPitch = 90.0; 208 | } 209 | 210 | this.pitch = nPitch; 211 | this.yaw = nYaw; 212 | } 213 | } 214 | 215 | /// 缩放视野。 216 | public Scale(nDelta, nWidth, nHeight): void { 217 | if (!this.m_nEnabled) { 218 | return; 219 | } 220 | 221 | let nDistance = this.distance; 222 | nDistance += nDelta * nDistance * 0.05; 223 | 224 | this.distance = nDistance; 225 | } 226 | 227 | /// 应用最新设置的参数,更新摄像机状态 228 | public Update(): void { 229 | if (!this.m_nEnabled) { 230 | return; 231 | } 232 | 233 | let bSpeed = 0.1 * MiaokitJS.App.m_nSensitivity; 234 | 235 | /// 非漫游模式:控制类似 236 | if (CTRL_MODE.WANDER !== this.m_eCtrlMode) { 237 | // 遥感模式:俯角强制调整为90度,偏航角强制调整为0度 238 | if (CTRL_MODE.REMOTE === this.m_eCtrlMode) { 239 | if (20000.0 > this.height) { 240 | this.m_eCtrlMode = CTRL_MODE.EAGLE; 241 | } 242 | else { 243 | let nBias = this.m_nPitch - 90.0; 244 | if (-0.1 > nBias || 0.1 < nBias) { 245 | this.m_nPitch -= nBias * bSpeed; 246 | } 247 | 248 | nBias = this.m_nYaw - 0.0; 249 | if (-0.1 > nBias || 0.1 < nBias) { 250 | this.m_nYaw -= nBias * bSpeed; 251 | } 252 | } 253 | } 254 | else if (CTRL_MODE.EAGLE === this.m_eCtrlMode) { 255 | if (20000.0 < this.distance) { 256 | this.m_eCtrlMode = CTRL_MODE.REMOTE; 257 | } 258 | else { 259 | let nBias = this.m_nPitch - 85.0; 260 | if (0.1 < nBias) { 261 | this.m_nPitch -= nBias * bSpeed; 262 | } 263 | 264 | nBias = 5.0 - this.m_nPitch; 265 | if (0.1 < nBias) { 266 | this.m_nPitch += nBias * bSpeed; 267 | } 268 | } 269 | } 270 | 271 | // 非全景模式:目标坐标强制调整为场景中心 272 | if (CTRL_MODE.PANORAMA !== this.m_eCtrlMode) { 273 | let mTarget = this.target; 274 | 275 | let nBias = mTarget.x - 0.0; 276 | if (-0.1 > nBias || 0.1 < nBias) { 277 | mTarget.x += nBias * bSpeed; 278 | } 279 | 280 | nBias = mTarget.y - 0.0; 281 | if (-0.1 > nBias || 0.1 < nBias) { 282 | mTarget.y += nBias * bSpeed; 283 | } 284 | 285 | nBias = mTarget.z - 0.0; 286 | if (-0.1 > nBias || 0.1 < nBias) { 287 | mTarget.z += nBias * bSpeed; 288 | } 289 | 290 | this.target = mTarget; 291 | } 292 | 293 | if (2 === this.m_nViewMode) { 294 | this.m_pTransform.position = { x: 0, y: 0, z: 0 }; 295 | this.m_pTransform.euler = { x: 0, y: 0, z: 0 }; 296 | this.m_pTransform.Rotate2({ x: 1, y: 0, z: 0 }, 90, 0); 297 | this.m_pTransform.position = this.target; 298 | this.m_pTransform.Translate(MiaokitJS.Vector3.Scale(-this.distance, { x: 0, y: 0, z: 1 }), 1); 299 | 300 | MiaokitJS.Miaokit.cameraTarget = this.target; 301 | } 302 | else { 303 | this.m_pTransform.position = { x: 0, y: 0, z: 0 }; 304 | this.m_pTransform.euler = { x: 0, y: 0, z: 0 }; 305 | this.m_pTransform.Rotate2({ x: 1, y: 0, z: 0 }, this.pitch, 1); 306 | this.m_pTransform.Rotate2({ x: 0, y: 1, z: 0 }, this.yaw, 0); 307 | this.m_pTransform.position = this.target; 308 | this.m_pTransform.Translate(MiaokitJS.Vector3.Scale(-this.distance, { x: 0, y: 0, z: 1 }), 1); 309 | 310 | MiaokitJS.Miaokit.cameraTarget = this.target; 311 | } 312 | } 313 | /// 漫游模式 314 | else { 315 | console.log("未实现漫游模式"); 316 | } 317 | } 318 | 319 | 320 | /// 设置摄像机控制器可控状态。 321 | public set enabled(enabled: boolean) { 322 | this.m_nEnabled = enabled; 323 | } 324 | 325 | /// 获取当前摄像机控制模式。 326 | public get ctrlMode(): CTRL_MODE { 327 | return this.m_eCtrlMode; 328 | } 329 | /// 设置当前摄像机控制模式。 330 | public set ctrlMode(mode: CTRL_MODE) { 331 | this.m_eCtrlMode = mode; 332 | } 333 | 334 | /// 视图模式。 335 | public get viewMode(): number { 336 | return this.m_nViewMode; 337 | } 338 | public set viewMode(mode: number) { 339 | if (this.m_nViewMode !== mode) { 340 | this.m_nViewMode = mode; 341 | MiaokitJS.Miaokit.cameraMode = mode; 342 | } 343 | } 344 | 345 | /// 获取当前摄像机状态。 346 | public get curView(): any { 347 | return { 348 | m_eCtrlMode: this.m_eCtrlMode, 349 | m_nLng: this.m_nLng, 350 | m_nLat: this.m_nLat, 351 | m_mTarget: this.m_mTarget, 352 | m_nDistance: this.m_nDistance, 353 | m_nPitch: this.m_nPitch, 354 | m_nYaw: this.m_nYaw 355 | } 356 | } 357 | 358 | /// 获取当前经度参数。 359 | public get lng(): number { 360 | return this.m_nLng; 361 | } 362 | /// 设置当前经度参数。 363 | public set lng(value) { 364 | this.m_nLng = value; 365 | } 366 | 367 | /// 获取当前经度参数。 368 | public get lat(): number { 369 | return this.m_nLat; 370 | } 371 | /// 设置当前经度参数。 372 | public set lat(value) { 373 | this.m_nLat = value; 374 | } 375 | 376 | /// 获取当前高度参数。 377 | public get height(): number { 378 | return this.m_nDistance; 379 | } 380 | /// 设置当前高度参数。仅REMOTE模式下设置生效。 381 | public set height(value) { 382 | if (CTRL_MODE.REMOTE === this.m_eCtrlMode) { 383 | this.m_nDistance = value; 384 | } 385 | } 386 | 387 | /// 获取当前距离参数。 388 | public get distance(): number { 389 | return this.m_nDistance; 390 | } 391 | /// 设置当前距离参数。仅REMOTE/EAGLE/PANORAMA模式下设置生效。 392 | public set distance(value) { 393 | if (CTRL_MODE.REMOTE === this.m_eCtrlMode || CTRL_MODE.EAGLE === this.m_eCtrlMode || CTRL_MODE.PANORAMA === this.m_eCtrlMode) { 394 | this.m_nDistance = value; 395 | } 396 | } 397 | 398 | /// 获取当前俯角参数。 399 | public get pitch(): number { 400 | return this.m_nPitch; 401 | } 402 | /// 设置当前俯角参数。仅EAGLE/PANORAMA/WANDER模式下设置生效。 403 | public set pitch(value) { 404 | if (CTRL_MODE.EAGLE === this.m_eCtrlMode || CTRL_MODE.PANORAMA === this.m_eCtrlMode || CTRL_MODE.WANDER === this.m_eCtrlMode) { 405 | this.m_nPitch = value; 406 | } 407 | } 408 | 409 | /// 获取当前偏航角参数。 410 | public get yaw(): number { 411 | return this.m_nYaw % 360.0; 412 | } 413 | /// 设置当前偏航角参数。仅EAGLE/PANORAMA/WANDER模式下设置生效。 414 | public set yaw(value) { 415 | if (CTRL_MODE.EAGLE === this.m_eCtrlMode || CTRL_MODE.PANORAMA === this.m_eCtrlMode || CTRL_MODE.WANDER === this.m_eCtrlMode) { 416 | this.m_nYaw = value; 417 | } 418 | } 419 | 420 | /// 获取当前目标坐标参数。 421 | public get target(): any { 422 | return { x: this.m_mTarget.x, y: this.m_mTarget.y, z: this.m_mTarget.z }; 423 | } 424 | /// 设置当前目标坐标参数。仅PANORAMA模式下设置生效。 425 | public set target(value) { 426 | if (CTRL_MODE.PANORAMA === this.m_eCtrlMode) { 427 | this.m_mTarget.x = value.x; 428 | this.m_mTarget.y = value.y; 429 | this.m_mTarget.z = value.z; 430 | } 431 | } 432 | 433 | /// 获取当前角色坐标参数。 434 | public get position(): any { 435 | return { x: this.m_mTarget.x, y: this.m_mTarget.y, z: this.m_mTarget.z }; 436 | } 437 | /// 设置当前角色坐标参数。仅WANDER模式下设置生效。 438 | public set position(value) { 439 | if (CTRL_MODE.WANDER === this.m_eCtrlMode) { 440 | this.m_mTarget.x = value.x; 441 | this.m_mTarget.y = value.y; 442 | this.m_mTarget.z = value.z; 443 | } 444 | } 445 | 446 | 447 | /// 摄像机对象。 448 | private m_pCamera: any = null; 449 | /// 摄像机变换组件。 450 | private m_pTransform: any = null; 451 | /// 摄像机控制启用状态。 452 | private m_nEnabled: boolean = true; 453 | 454 | /// 当前控制模式。 455 | private m_eCtrlMode: CTRL_MODE = CTRL_MODE.REMOTE; 456 | /// 当前视图模式。 457 | private m_nViewMode: number = 3; 458 | /// 当前经度参数。 459 | private m_nLng: number = 0.0; 460 | /// 当前经度参数。 461 | private m_nLat: number = 0.0; 462 | /// 当前距离参数。 463 | private m_nDistance: number = 0.0; 464 | /// 当前俯角参数。 465 | private m_nPitch: number = 0.0; 466 | /// 当前偏航角参数。 467 | private m_nYaw: number = 0.0; 468 | /// 当前目标坐标参数。 469 | private m_mTarget: any = { x: 0.0, y: 0.0, z: 0.0 }; 470 | } 471 | 472 | 473 | MiaokitJS.UTIL = MiaokitJS.UTIL || {}; 474 | MiaokitJS.UTIL.CTRL_MODE = CTRL_MODE; 475 | MiaokitJS.UTIL.VIEW_MODE = VIEW_MODE; 476 | MiaokitJS.UTIL.RemoteParam = RemoteParam; 477 | MiaokitJS.UTIL.EagleParam = EagleParam; 478 | MiaokitJS.UTIL.PanoramaParam = PanoramaParam; 479 | MiaokitJS.UTIL.WanderParam = WanderParam; 480 | MiaokitJS.UTIL.CameraCtrl = CameraCtrl; 481 | -------------------------------------------------------------------------------- /web/private/common/util/framework.ts: -------------------------------------------------------------------------------- 1 |  2 | declare var MiaokitJS: any; 3 | 4 | class App { 5 | /// 构造函数。 6 | public constructor() { 7 | } 8 | 9 | /// 数据预加载。 10 | public Preload(): void { 11 | this.m_pProject.Preload(); 12 | } 13 | 14 | /// SVE核心逻辑功能启动。 15 | public Start(): void { 16 | let pContainer = document.getElementById("unityContainer"); 17 | 18 | let pCanvas2D = document.createElement("canvas"); 19 | pCanvas2D.id = "2d"; 20 | pCanvas2D.width = pContainer.offsetWidth; 21 | pCanvas2D.height = pContainer.offsetHeight; 22 | pCanvas2D.style.width = "100%"; 23 | pCanvas2D.style.height = "100%"; 24 | pCanvas2D.style.top = "0rem"; 25 | pCanvas2D.style.bottom = "0rem"; 26 | pCanvas2D.style.left = "0rem"; 27 | pCanvas2D.style.right = "0rem"; 28 | pCanvas2D.style.position = "absolute"; 29 | pCanvas2D.style.zIndex = "1"; 30 | 31 | pContainer.appendChild(pCanvas2D); 32 | 33 | MiaokitJS["Miaokit"]["ResizeCavans"](pCanvas2D.width, pCanvas2D.height); 34 | 35 | this.m_pContainer = pContainer; 36 | this.m_pCanvas2D = pCanvas2D; 37 | this.m_pCanvasCtx2D = pCanvas2D.getContext('2d'); 38 | 39 | this.m_pCamera = MiaokitJS.Miaokit.camera; 40 | this.m_pCameraCtrl = new MiaokitJS.UTIL.CameraCtrl(this.m_pCamera); 41 | 42 | this.m_pPanoramas = MiaokitJS.Miaokit.panoramas; 43 | 44 | if (MiaokitJS.m_pConfig.GIS) { 45 | let pConfig = MiaokitJS.m_pConfig.GIS[0]; 46 | 47 | this.m_pGis = MiaokitJS.Miaokit.gis; 48 | this.m_pGis.imageServer = pConfig.m_pImageServer; 49 | 50 | if (pConfig.m_pLabelServer) { 51 | this.m_pGis.labelServer = pConfig.m_pLabelServer; 52 | } 53 | 54 | if (pConfig.m_pTerrainServer) { 55 | this.m_pGis.terrainServer = pConfig.m_pTerrainServer; 56 | } 57 | } 58 | 59 | this.RegisterEvent(this.m_pCanvas2D, MiaokitJS.Miaokit.cameraCtrl); 60 | this.m_pProject.Start(); 61 | } 62 | 63 | /// SVE核心逻辑功能帧更新。 64 | public Update(): void { 65 | this.m_nTick++; 66 | this.Draw2D(); 67 | this.m_pCameraCtrl.Update(); 68 | this.m_pProject.Update(); 69 | } 70 | 71 | /// 切换GIS样式。 72 | public SwitchGIS(nType): void { 73 | if (MiaokitJS.m_pConfig.GIS) { 74 | let pConfig = MiaokitJS.m_pConfig.GIS[nType]; 75 | if (pConfig) { 76 | this.m_pGis.SwitchStyle(8 + 4 + 2 + 1); 77 | 78 | this.m_pGis.imageServer = pConfig.m_pImageServer; 79 | 80 | if (pConfig.m_pLabelServer) { 81 | this.m_pGis.labelServer = pConfig.m_pLabelServer; 82 | } 83 | 84 | if (pConfig.m_pTerrainServer) { 85 | this.m_pGis.terrainServer = pConfig.m_pTerrainServer; 86 | } 87 | 88 | this.m_pProject.OnGisSwitch(); 89 | } 90 | } 91 | } 92 | 93 | 94 | /// 绘制2D画布。 95 | private Draw2D(): void { 96 | this.m_pCanvasCtx2D.clearRect(0, 0, this.m_pCanvas2D.clientWidth, this.m_pCanvas2D.clientHeight); 97 | this.Analyze(); 98 | 99 | this.m_pProject.OnGUI(this.m_pCanvas2D, this.m_pCanvasCtx2D); 100 | 101 | if (this.OnGUI) { 102 | this.OnGUI(this.m_pCanvas2D, this.m_pCanvasCtx2D); 103 | } 104 | } 105 | 106 | /// 显示运行情况分析数据。 107 | private Analyze(): void { 108 | if (1 === this.m_nTick % 60) { 109 | let nTime = MiaokitJS.Time(); 110 | 111 | if (this.m_nTime) { 112 | this.m_nFPS = 60 / ((nTime - this.m_nTime) / 1000); 113 | this.m_nSensitivity = 60 / this.m_nFPS; 114 | this.m_aAnalyze = MiaokitJS.Miaokit.Analyze(this.m_nFPS.toFixed(0)); 115 | this.m_nTime = nTime; 116 | } 117 | else { 118 | this.m_aAnalyze = MiaokitJS.Miaokit.Analyze(1); 119 | this.m_nTime = nTime; 120 | } 121 | } 122 | 123 | let pCanvas = this.m_pCanvasCtx2D; 124 | let aInfo = this.m_aAnalyze; 125 | let nOffset = 68; 126 | 127 | if (aInfo) { 128 | pCanvas.font = "14px Microsoft YaHei"; 129 | pCanvas.strokeStyle = "black"; 130 | pCanvas.lineWidth = 2; 131 | pCanvas.fillStyle = "#FFFFFF"; 132 | 133 | for (let pInfo of aInfo) { 134 | pCanvas.strokeText(pInfo, 10, nOffset); 135 | pCanvas.fillText(pInfo, 10, nOffset); 136 | nOffset += 18; 137 | } 138 | 139 | if (MiaokitJS.Profiler) { 140 | let pInfo = MiaokitJS.Profiler.m_pMsg; 141 | pCanvas.strokeText(pInfo, 10, nOffset); 142 | pCanvas.fillText(pInfo, 10, nOffset); 143 | nOffset += 18; 144 | } 145 | 146 | } 147 | } 148 | 149 | /// 注册交互事件。 150 | private RegisterEvent(pCavans: HTMLElement, pCamera): void { 151 | // -1=不响应,2=旋转,0=平移,1=缩放 152 | let nDrag = -1; 153 | // 鼠标按键按下计时 154 | let nPressTime = MiaokitJS.Time(); 155 | // 鼠标按键上一次单击时间 156 | let nClickTime = 0; 157 | let pThis = this; 158 | 159 | let pLastObj = null; 160 | 161 | pCavans.addEventListener("mousewheel", function (e: WheelEvent) { 162 | pThis.m_pCameraCtrl.Scale(e.deltaY / Math.abs(e.deltaY), pThis.m_pCanvas2D.clientWidth, pThis.m_pCanvas2D.clientHeight); 163 | }, true); 164 | /// 火狐浏览器的鼠标滚轮事件。 165 | pCavans.addEventListener("DOMMouseScroll", function (e: WheelEvent) { 166 | pThis.m_pCameraCtrl.Scale(e.detail / Math.abs(e.detail), pThis.m_pCanvas2D.clientWidth, pThis.m_pCanvas2D.clientHeight); 167 | }, true); 168 | /*pCavans.addEventListener("mousedown",*/ pCavans.onmousedown = function (e: MouseEvent) { 169 | nDrag = e.button; 170 | if (2 === nDrag) { 171 | nDrag = 1; 172 | } 173 | nPressTime = MiaokitJS.Time(); 174 | }/*, false)*/; 175 | /*pCavans.addEventListener("mouseup",*/ pCavans.onmouseup = function (e: MouseEvent) { 176 | nDrag = -1; 177 | if (250 > MiaokitJS.Time() - nPressTime) { 178 | /// 鼠标双击 179 | if (500 > MiaokitJS.Time() - nClickTime) { 180 | pThis.m_pProject.OnClick(2, e); 181 | } 182 | /// 鼠标单击 183 | else { 184 | pThis.m_pProject.OnClick(1, e); 185 | } 186 | 187 | nClickTime = MiaokitJS.Time(); 188 | } 189 | }/*, false)*/; 190 | /*pCavans.addEventListener("mouseout",*/ pCavans.onmouseout = function (e: MouseEvent) { 191 | nDrag = -1; 192 | }/*, false)*/; 193 | /*pCavans.addEventListener("mousemove",*/ pCavans.onmousemove = function (e: MouseEvent) { 194 | MiaokitJS.ShaderLab.Pipeline.Picker = { 195 | Feedback: (pObject, nSubmesh) => { 196 | if (pObject) { 197 | if (!pLastObj || pLastObj.m_nID !== pObject.m_nID) { 198 | if (pLastObj) { 199 | pLastObj.highlight = false; 200 | } 201 | 202 | console.log(pObject.name, nSubmesh); 203 | pObject.highlight = true; 204 | 205 | pLastObj = pObject; 206 | } 207 | } 208 | }, 209 | x: e.clientX, 210 | y: e.clientY 211 | }; 212 | 213 | if (0 === nDrag) { 214 | pThis.m_pCameraCtrl.Move(-e.movementX, e.movementY, pThis.m_pCanvas2D.clientWidth, pThis.m_pCanvas2D.clientHeight); 215 | 216 | if (pThis.m_pProject.OnDrag) { 217 | pThis.m_pProject.OnDrag(-e.movementX, e.movementY, pThis.m_pCanvas2D.clientWidth, pThis.m_pCanvas2D.clientHeight); 218 | } 219 | } 220 | else if (1 === nDrag) { 221 | pThis.m_pCameraCtrl.Rotate(e.movementX, e.movementY, pThis.m_pCanvas2D.clientWidth, pThis.m_pCanvas2D.clientHeight); 222 | } 223 | }/*, false)*/; 224 | 225 | 226 | let pStartEvent: TouchEvent = null; 227 | let Distance = function (p0, p1): number { 228 | let mVec = { x: p0.x - p1.x, y: p0.y - p1.y }; 229 | 230 | return Math.sqrt((mVec.x * mVec.x) + (mVec.y * mVec.y)); 231 | } 232 | 233 | /*pCavans.addEventListener("touchstart", */pCavans.ontouchstart = function (e: TouchEvent) { 234 | if (1 == e.touches.length) { 235 | nDrag = 2; 236 | pStartEvent = e; 237 | } 238 | else if (2 == e.touches.length) { 239 | } 240 | }/*, false)*/; 241 | /*pCavans.addEventListener("touchmove", */pCavans.ontouchmove = function (e: TouchEvent) { 242 | e.preventDefault(); 243 | if (e.touches == null) 244 | return; 245 | if (1 == e.touches.length && 2 == nDrag) { 246 | let nDeltaX = e.touches[0].clientX - pStartEvent.touches[0].clientX; 247 | let nDeltaY = e.touches[0].clientY - pStartEvent.touches[0].clientY; 248 | 249 | pStartEvent = e; 250 | 251 | pThis.m_pCameraCtrl.Move(nDeltaX * -2, nDeltaY * 2, pThis.m_pCanvas2D.clientWidth, pThis.m_pCanvas2D.clientHeight); 252 | 253 | if (pThis.m_pProject.OnDrag) { 254 | pThis.m_pProject.OnDrag(nDeltaX * -2, nDeltaY * 2, pThis.m_pCanvas2D.clientWidth, pThis.m_pCanvas2D.clientHeight); 255 | } 256 | } 257 | else if (2 == e.touches.length && 2 == pStartEvent.touches.length) { 258 | let mStartPoint = { x: (pStartEvent.touches[0].clientX + pStartEvent.touches[1].clientX) * 0.5, y: (pStartEvent.touches[0].clientY + pStartEvent.touches[1].clientY) * 0.5 }; 259 | let mCurPoint = { x: (e.touches[0].clientX + e.touches[1].clientX) * 0.5, y: (e.touches[0].clientY + e.touches[1].clientY) * 0.5 }; 260 | let mMoveDelta = { x: -mCurPoint.x + mStartPoint.x, y: mCurPoint.y - mStartPoint.y }; 261 | 262 | let mStartPoint0 = { x: pStartEvent.touches[0].clientX, y: pStartEvent.touches[0].clientY }; 263 | let mStartPoint1 = { x: pStartEvent.touches[1].clientX, y: pStartEvent.touches[1].clientY }; 264 | let mCurPoint0 = { x: e.touches[0].clientX, y: e.touches[0].clientY }; 265 | let mCurPoint1 = { x: e.touches[1].clientX, y: e.touches[1].clientY }; 266 | let nScaleDelta = Distance(mCurPoint0, mCurPoint1) - Distance(mStartPoint1, mStartPoint0); 267 | 268 | pStartEvent = e; 269 | 270 | pThis.m_pCameraCtrl.Rotate(mMoveDelta.x * -5, mMoveDelta.y * 5, pThis.m_pCanvas2D.clientWidth, pThis.m_pCanvas2D.clientHeight); 271 | 272 | if (Math.abs(nScaleDelta) > 10) { 273 | pThis.m_pCameraCtrl.Scale(-nScaleDelta / Math.abs(nScaleDelta), pThis.m_pCanvas2D.clientWidth, pThis.m_pCanvas2D.clientHeight); 274 | } 275 | } 276 | else { 277 | pStartEvent = e; 278 | } 279 | }/*, false)*/; 280 | /*pCavans.addEventListener("touchend", */pCavans.ontouchend = function (e: TouchEvent) { nDrag = -1; pStartEvent = null; }/*, false)*/; 281 | } 282 | 283 | 284 | /// 画布容器。 285 | public m_pContainer: any = null; 286 | /// 2D画布,接收鼠标事件。 287 | public m_pCanvas2D: any = null; 288 | /// 2D画布上下文,用户绘制标签文字。 289 | public m_pCanvasCtx2D: any = null; 290 | /// 响应2D画布绘制。 291 | public OnGUI: any = null; 292 | 293 | /// 帧数统计。 294 | private m_nTick: any = null; 295 | /// 60帧时间统计。 296 | private m_nTime: number = 0; 297 | /// 分析数据。 298 | private m_aAnalyze: any = null; 299 | /// 最新帧率。 300 | private m_nFPS: number = 60; 301 | /// 最新灵敏度。 302 | private m_nSensitivity: number = 1.0; 303 | 304 | /// 摄像机对象。 305 | private m_pCamera: any = null; 306 | /// 摄像机控制器。 307 | private m_pCameraCtrl: any = null; 308 | /// GIS对象。 309 | private m_pGis: any = null; 310 | /// 全景图对象。 311 | private m_pPanoramas: any = null; 312 | /// 项目逻辑对象。 313 | private m_pProject: any = null; 314 | } 315 | 316 | 317 | MiaokitJS.UTIL = MiaokitJS.UTIL || {}; 318 | MiaokitJS.UTIL.App = App; 319 | MiaokitJS.App = new App(); 320 | -------------------------------------------------------------------------------- /web/private/common/util/pipeline.ts: -------------------------------------------------------------------------------- 1 | 2 | MiaokitJS.ShaderLab.Pipeline = { 3 | RenderTarget: [null, 4 | /// 1.绘制不透明物体颜色缓存 5 | { ID: 1, Format: "RGBA16_FLOAT" }, 6 | /// 2.绘制半透明物体颜色缓存/轮廓与高光颜色缓存 7 | { ID: 2, Format: "RGBA16_FLOAT" }, 8 | /// 3.绘制不透明物体深度缓存 9 | { ID: 3, Format: "D24_UNORM" }, 10 | /// 4.高光输入缓存,降采样,需生成MIPMAP 11 | { ID: 4, Format: "RGBA16_FLOAT", Width: 1024, Height: 1024, Params: ["LINEAR_MIPMAP_LINEAR", "LINEAR", "CLAMP_TO_EDGE", "CLAMP_TO_EDGE"] }, 12 | /// 5.高光模输出缓存,升采样512->X 13 | { ID: 5, Format: "RGBA16_FLOAT" }, 14 | /// 6.高光模糊缓存,升采样256->512 15 | { ID: 6, Format: "RGBA16_FLOAT", Width: 512, Height: 512, Params: ["LINEAR", "LINEAR", "CLAMP_TO_EDGE", "CLAMP_TO_EDGE"] }, 16 | /// 7.高光模糊缓存,升采样128->256 17 | { ID: 7, Format: "RGBA16_FLOAT", Width: 256, Height: 256, Params: ["LINEAR", "LINEAR", "CLAMP_TO_EDGE", "CLAMP_TO_EDGE"] }, 18 | /// 8.高光模糊缓存,升采样64->128 19 | { ID: 8, Format: "RGBA16_FLOAT", Width: 128, Height: 128, Params: ["LINEAR", "LINEAR", "CLAMP_TO_EDGE", "CLAMP_TO_EDGE"] }, 20 | /// 9.半透明与不透明混合颜色缓存 21 | { ID: 9, Format: "RGBA16_FLOAT" }, 22 | ], 23 | 24 | Resource: [null, 25 | /// 1.星空背景贴图 26 | { ID: 1, TYPE: "2D", URL: "./data/projects/images/star.jpg" }, 27 | /// 2.默认贴图 28 | { ID: 2, TYPE: "2D", URL: "./data/projects/images/default.png" } 29 | ], 30 | 31 | PassList: [ 32 | // 0、->1,清空画布,绘制天空盒。 33 | { 34 | Name: "绘制天空盒", 35 | Type: "Clear", 36 | Mask: ["Opaque"], 37 | RenderTarget: [1, 0], 38 | ClearTarget: { 39 | Color: { r: 0.198, g: 0.323, b: 0.561, a: 1.0 } 40 | }, 41 | }, 42 | // 1、->1,绘制不透明物体。 43 | { 44 | Name: "绘制不透明物体", 45 | Type: "Render", 46 | Mask: ["Opaque"], 47 | RenderTarget: [1, 3], 48 | ClearTarget: { 49 | Depth: 1.0 50 | }, 51 | Depth: { 52 | Func: "LEQUAL", 53 | Write: true 54 | }, 55 | }, 56 | // 2、->2,绘制半透明物体。 57 | { 58 | Name: "绘制半透明物体", 59 | Type: "Render", 60 | Mask: ["Transparent"], 61 | RenderTarget: [2, 3], 62 | ClearTarget: { 63 | Color: { r: 0.0, g: 0.0, b: 0.0, a: 1.0 }, 64 | }, 65 | Depth: { 66 | Func: "LEQUAL", 67 | Write: false 68 | }, 69 | Blend: { 70 | ColorFunc: "FUNC_ADD", 71 | ColorSrc: "ONE", 72 | ColorDest: "ONE", 73 | AlphaFunc: "FUNC_ADD", 74 | AlphaSrc: "ZERO", 75 | AlphaDest: "SRC_ALPHA", 76 | } 77 | }, 78 | // 3、1+2->9,混合不透明与半透明缓存。 79 | { 80 | Name: "混合不透明与半透明缓存", 81 | Type: "Postprocess", 82 | Mask: [], 83 | RenderTarget: [9, 0], 84 | Shader: "Combine", 85 | SetUniforms: function (aAttr, gl: WebGLRenderingContext) { 86 | let aTarget = MiaokitJS.ShaderLab.Pipeline.RenderTarget; 87 | 88 | aAttr[8]("u_MainTex", [0, aTarget[1].Handle, 0, 0]); 89 | aAttr[8]("u_MinorTex", [0, aTarget[2].Handle, 0, 0]); 90 | } 91 | }, 92 | // 4、9->2,后期处理,提取物体轮廓,抗锯齿,高亮。 93 | { 94 | Name: "提取物体轮廓", 95 | Type: "Postprocess", 96 | Mask: [], 97 | RenderTarget: [2, 3], 98 | Shader: "EdgeDetection", 99 | SetUniforms: function (aAttr, gl: WebGLRenderingContext) { 100 | let aTarget = MiaokitJS.ShaderLab.Pipeline.RenderTarget; 101 | 102 | aAttr[8]("u_MainTex", [0, aTarget[9].Handle, 0, 0]); 103 | aAttr[8]("u_InvTexSize", aTarget[9].Size); 104 | } 105 | }, 106 | // 5、2->4,后期处理,提取画面高光部分。 107 | { 108 | Name: "提取画面高光部分", 109 | Type: "Postprocess", 110 | Mask: [], 111 | RenderTarget: [4, 0], 112 | Shader: "HDR", 113 | SetUniforms: function (aAttr, gl: WebGLRenderingContext) { 114 | let aTarget = MiaokitJS.ShaderLab.Pipeline.RenderTarget; 115 | 116 | aAttr[8]("u_MainTex", [0, aTarget[2].Handle, 0, 0]); 117 | }, 118 | Postprocess: (gl: WebGLRenderingContext) => { 119 | gl.bindTexture(gl.TEXTURE_2D, MiaokitJS.ShaderLab.Pipeline.RenderTarget[4].Texture); 120 | gl.generateMipmap(gl.TEXTURE_2D) 121 | gl.bindTexture(gl.TEXTURE_2D, null); 122 | } 123 | }, 124 | // 6、4->8->7->6->5,后期处理,模糊高光(经过4个通道处理)。 125 | { 126 | Name: "模糊高光", 127 | Type: "Postprocess", 128 | Mask: [], 129 | Shader: "Upsampling", 130 | PingpongCount: 1, 131 | Pingpong: [ 132 | { 133 | RenderTarget: [8, 0], 134 | SetUniforms: function (aAttr, gl: WebGLRenderingContext) { 135 | let pTarget4 = MiaokitJS.ShaderLab.Pipeline.RenderTarget[4]; 136 | 137 | aAttr[8]("u_MainTex", [0, pTarget4.Handle, 0, 0]); 138 | aAttr[8]("u_MinorTex", [0, pTarget4.Handle, 0, 0]); 139 | aAttr[8]("u_InvTexSize", [1.0 / 64.0, 1.0 / 64.0, 4.0, 3.0]); 140 | } 141 | }, 142 | { 143 | RenderTarget: [7, 0], 144 | SetUniforms: function (aAttr, gl: WebGLRenderingContext) { 145 | aAttr[8]("u_MinorTex", [0, MiaokitJS.ShaderLab.Pipeline.RenderTarget[8].Handle, 0, 0]); 146 | aAttr[8]("u_InvTexSize", [1.0 / 128.0, 1.0 / 128.0, 0.0, 2.0]); 147 | } 148 | }, 149 | { 150 | RenderTarget: [6, 0], 151 | SetUniforms: function (aAttr, gl: WebGLRenderingContext) { 152 | aAttr[8]("u_MinorTex", [0, MiaokitJS.ShaderLab.Pipeline.RenderTarget[7].Handle, 0, 0]); 153 | aAttr[8]("u_InvTexSize", [1.0 / 256.0, 1.0 / 256.0, 0.0, 1.0]); 154 | } 155 | }, 156 | { 157 | RenderTarget: [5, 0], 158 | SetUniforms: function (aAttr, gl: WebGLRenderingContext) { 159 | aAttr[8]("u_MinorTex", [0, MiaokitJS.ShaderLab.Pipeline.RenderTarget[6].Handle, 0, 0]); 160 | aAttr[8]("u_InvTexSize", [1.0 / 512.0, 1.0 / 512.0, 0.0, 0.0]); 161 | } 162 | } 163 | ] 164 | }, 165 | // 7、2+5->,后期处理,提交图像。 166 | { 167 | Name: "提交图像", 168 | Type: "Postprocess", 169 | Mask: [], 170 | Shader: "Present", 171 | SetUniforms: function (aAttr, gl: WebGLRenderingContext) { 172 | let aTarget = MiaokitJS.ShaderLab.Pipeline.RenderTarget; 173 | 174 | aAttr[8]("u_MainTex", [0, aTarget[2].Handle, 0, 0]); 175 | aAttr[8]("u_MinorTex", [0, aTarget[5].Handle, 0, 0]); 176 | } 177 | } 178 | ], 179 | 180 | InternalShader: [ 181 | "Default", /*00*/ "Wall", /*01*/ "Wall", /*02*/ "Default", /*03*/ 182 | "Default", /*04*/ "Default", /*05*/ "Default", /*06*/ "GIS", /*07*/ 183 | "Mapbox", /*08*/ "RoomPanor", /*09*/ "Dioramas", /*10*/ "Panoramas", /*11*/ 184 | "Cosmos", /*12*/ "Ground", /*13*/ "Sky", /*14*/ "Present" /*15*/ 185 | ], 186 | 187 | Init: function () { 188 | let nQuality = MiaokitJS.m_pConfig.QUALITY; 189 | let pPipeline = MiaokitJS.ShaderLab.Pipeline; 190 | 191 | // 高品质 192 | if (2 === nQuality) { 193 | let aPass = pPipeline.PassList; 194 | pPipeline.HighQuality = [ 195 | aPass[0], 196 | aPass[1], 197 | aPass[2], 198 | aPass[3], 199 | aPass[4], 200 | aPass[5], 201 | aPass[6], 202 | aPass[7] 203 | ]; 204 | pPipeline.Pass = pPipeline.HighQuality; 205 | 206 | } 207 | // 中品质 208 | else if (1 === nQuality) { 209 | let aPass = pPipeline.PassList; 210 | pPipeline.MediumQuality = [ 211 | aPass[0], 212 | aPass[1], 213 | aPass[2], 214 | aPass[3], 215 | aPass[4], 216 | aPass[5], 217 | aPass[6], 218 | aPass[7] 219 | ]; 220 | pPipeline.Pass = pPipeline.MediumQuality; 221 | } 222 | // 低品质 223 | else { 224 | //let aTarget = pPipeline.RenderTarget; 225 | //aTarget[1].Width = 640; 226 | //aTarget[1].Height = 1024; 227 | //aTarget[2].Width = 640; 228 | //aTarget[2].Height = 1024; 229 | //aTarget[3].Width = 640; 230 | //aTarget[3].Height = 1024; 231 | //aTarget[9].Width = 640; 232 | //aTarget[9].Height = 1024; 233 | // 新的方式,rgb做混合参数和色值,不透明高亮,明确的1、0,透明高亮,也给予明确的0或1, 234 | let aPass = pPipeline.PassList; 235 | aPass[3].RenderTarget = undefined; 236 | //aPass[1].ClearTarget.Color = { r: 0.198, g: 0.323, b: 0.45, a: 0.0 }; 237 | pPipeline.LowQuality = [ 238 | aPass[0], 239 | aPass[1], 240 | aPass[2], 241 | aPass[3] 242 | ]; 243 | pPipeline.Pass = pPipeline.LowQuality; 244 | } 245 | }, 246 | 247 | HighQuality: null, 248 | MediumQuality: null, 249 | LowQuality: null, 250 | Pass: null, 251 | Picker: null 252 | }; 253 | 254 | 255 | let PNT_SPHERE = ` 256 | // 左上角经度、左上角纬度、经度跨距、纬度跨距 257 | uniform vec4 u_LngLat; 258 | 259 | varying vec4 v_Position; 260 | varying vec4 v_Normal; 261 | varying vec4 v_UV; 262 | 263 | vec4 SPHERE(float nTessell) 264 | { 265 | float nLng = u_LngLat.x + u_LngLat.z * a_Position.x; 266 | float nLat = u_LngLat.y - u_LngLat.w * a_Position.y; 267 | 268 | float nY = sin(nLat); 269 | float nX = cos(nLat) * cos(nLng); 270 | float nZ = cos(nLat) * sin(nLng); 271 | 272 | v_Normal.xyz = vec3(nX, nY, nZ); 273 | v_Position.xyz = ObjectToWorldPos(v_Normal.xyz); 274 | v_UV = vec4(a_Position.xy / 64.0, 0.0, 0.0); 275 | 276 | v_Normal.w = 0.0; 277 | v_Position.w = 0.0; 278 | 279 | return u_MatVP * a_MatW * vec4(v_Normal.xyz, 1.0); 280 | } 281 | `; 282 | 283 | let LIGHT_VS = ` 284 | #ifdef HIGH_QUALITY 285 | varying vec3 v_Position; 286 | varying vec3 v_Normal; 287 | 288 | void LightVS(vec3 mPosition, vec3 mNormal) 289 | { 290 | v_Normal = mNormal; 291 | v_Position = mPosition.xyz; 292 | 293 | Atmosphere(normalize(u_Sunlight.xyz), mPosition.xyz); 294 | } 295 | #endif 296 | `; 297 | 298 | let LIGHT_FS = ` 299 | #ifdef HIGH_QUALITY 300 | varying vec3 v_Position; 301 | varying vec3 v_Normal; 302 | 303 | vec4 LightFS(vec4 mColor) 304 | { 305 | vec3 _ViewDir = normalize(u_EyePos.xyz - v_Position.xyz); 306 | vec3 _Light = normalize(u_Sunlight.xyz); 307 | 308 | // 实景模型法线计算不严谨,会有非法值出现 309 | vec3 _Normal = normalize(vec3(v_Normal.x, v_Normal.y + 0.1, v_Normal.z)); 310 | vec3 _Tangent = vec3(0.0, 0.0, 1.0); 311 | vec3 _Binormal = vec3(1.0, 0.0, 0.0); 312 | if(0.7 > _Normal.y) 313 | { 314 | _Tangent = normalize(cross(_Normal, vec3(0.0, 1.0, 0.0))); 315 | _Binormal = normalize(cross(_Tangent, _Normal)); 316 | } 317 | 318 | mColor.rgb += BRDF(_Light, _ViewDir, _Normal, _Tangent, _Binormal) * 0.4; 319 | 320 | mColor = AtmosphereLight(mColor, _Light); 321 | mColor.a = 1.0; 322 | 323 | return mColor; 324 | } 325 | #endif 326 | `; 327 | 328 | 329 | MiaokitJS.Shader["Default"] = { 330 | name: "Default", 331 | type: "Render", 332 | mark: ["Opaque"], 333 | include: [ 334 | null, 335 | null, 336 | ["ATOM", "BRDF"], 337 | ], 338 | vs_src: LIGHT_VS + ` 339 | varying vec4 v_UV; 340 | 341 | vec4 vs() 342 | { 343 | v_UV = vec4(a_UV, 0.0, 0.0); 344 | 345 | vec4 mPosition = vec4(a_Position.xyz, 1.0); 346 | mPosition = u_MatG * a_MatW * mPosition; 347 | mPosition.xyz += u_GisBias.xyz; 348 | 349 | #ifdef HIGH_QUALITY 350 | LightVS(mPosition.xyz, ObjectToWorldNormal(a_Normal)); 351 | #endif 352 | 353 | return u_MatVP * mPosition; 354 | } 355 | `, 356 | fs_src: LIGHT_FS + ` 357 | varying vec4 v_UV; 358 | 359 | vec4 fs() 360 | { 361 | vec4 mColor = Tex2D(u_MainTex, v_UV.xy); 362 | mColor.rgb *= 0.85; 363 | 364 | #ifdef HIGH_QUALITY 365 | mColor = LightFS(mColor); 366 | #endif 367 | 368 | return mColor; 369 | } 370 | ` 371 | }; 372 | 373 | MiaokitJS.Shader["Wall"] = { 374 | name: "Wall", 375 | type: "Render", 376 | mark: ["Opaque"], 377 | vs_src: ` 378 | varying vec3 v_Normal; 379 | 380 | vec4 vs() 381 | { 382 | v_Normal = ObjectToWorldNormal(a_Normal); 383 | 384 | vec4 mPosition = vec4(a_Position.xyz, 1.0); 385 | mPosition = u_MatG * a_MatW * mPosition; 386 | mPosition.xyz += u_GisBias.xyz; 387 | 388 | return u_MatVP * mPosition; 389 | } 390 | `, 391 | fs_src: ` 392 | varying vec3 v_Normal; 393 | 394 | vec4 fs() 395 | { 396 | vec4 mColor = vec4(0.9255, 0.9412, 0.9647, 1.0); 397 | float nDiffuse = clamp(dot(v_Normal, normalize(u_Sunlight.xyz)), 0.0, 1.0); 398 | 399 | nDiffuse = nDiffuse * 0.4 + 0.3; 400 | nDiffuse *= 1.8; 401 | mColor.rgb *= nDiffuse; 402 | 403 | return mColor; 404 | } 405 | ` 406 | }; 407 | 408 | MiaokitJS.Shader["Corner"] = { 409 | name: "Corner", 410 | type: "Render", 411 | mark: ["Transparent"], 412 | vs_src: ` 413 | vec4 vs() 414 | { 415 | return ObjectToClipPos(a_Position.xyz); 416 | } 417 | `, 418 | fs_src: ` 419 | vec4 fs() 420 | { 421 | return vec4(1.98, 3.23, 5.61, 1.0); 422 | } 423 | ` 424 | }; 425 | 426 | MiaokitJS.Shader["Mapbox"] = { 427 | name: "Mapbox", 428 | type: "Render", 429 | mark: ["Opaque"], 430 | vs_src: ` 431 | vec4 vs() 432 | { 433 | return ObjectToClipPos(a_Position.xyz); 434 | } 435 | `, 436 | fs_src: ` 437 | vec4 fs() 438 | { 439 | return vec4(0.6019608, 0.7862745, 0.8254902, 1.0); 440 | } 441 | ` 442 | }; 443 | 444 | MiaokitJS.Shader["Mapbox2"] = { 445 | name: "Mapbox2", 446 | type: "Render", 447 | mark: ["Opaque"], 448 | vs_src: ` 449 | vec4 vs() 450 | { 451 | return ObjectToClipPos(a_Position.xyz); 452 | } 453 | `, 454 | fs_src: ` 455 | vec4 fs() 456 | { 457 | return vec4(0.6019608, 0.7862745, 0.8254902, 1.0); 458 | } 459 | ` 460 | }; 461 | 462 | MiaokitJS.Shader["Dioramas"] = { 463 | name: "Dioramas", 464 | type: "Render", 465 | mark: ["Opaque"], 466 | include: [ 467 | null, 468 | null, 469 | ["ATOM", "BRDF"], 470 | ], 471 | vs_src: LIGHT_VS + ` 472 | uniform sampler2D _BuildingTex; 473 | 474 | varying vec4 v_UV; 475 | 476 | vec4 vs() 477 | { 478 | vec4 mBuilding = texture2D(_BuildingTex, a_Normal.xy); 479 | 480 | //v_Object.a = mBuilding.r; 481 | v_UV = vec4(a_UV, 0.0, 0.0); 482 | 483 | vec4 mPosition = vec4(a_Position.xyz, 1.0); 484 | mPosition = u_MatG * a_MatW * mPosition; 485 | mPosition.y -= mBuilding.r * (mPosition.y - 177.0); 486 | mPosition.xyz += u_GisBias.xyz; 487 | 488 | // 高品质下,计算法线,计算大气散射 489 | #ifdef HIGH_QUALITY 490 | float n = a_Normal.z; 491 | float nx = n / 8.0; n = floor(nx); nx = (nx - n) * 4.0 - 1.0; 492 | float ny = n / 8.0; n = floor(ny); ny = (ny - n) * 4.0 - 1.0; 493 | float nz = (n - 2.0) * 0.5; 494 | 495 | LightVS(mPosition.xyz, vec3(nx, ny, nz)); 496 | #endif 497 | 498 | return u_MatVP * mPosition; 499 | } 500 | `, 501 | fs_src: LIGHT_FS + ` 502 | varying vec4 v_UV; 503 | 504 | vec4 fs() 505 | { 506 | vec4 mColor = Tex2D(u_MainTex, v_UV.xy); 507 | 508 | #ifdef HIGH_QUALITY 509 | mColor = LightFS(mColor); 510 | #endif 511 | 512 | return mColor; 513 | } 514 | ` 515 | }; 516 | 517 | MiaokitJS.Shader["GIS"] = { 518 | name: "GIS", 519 | type: "Render", 520 | mark: ["Opaque"], 521 | include: [ 522 | null, 523 | null, 524 | ["ATOM", "BRDF"], 525 | ], 526 | vs_src: ` 527 | uniform sampler2D _TerrainTex; 528 | uniform vec4 _LngLat; 529 | uniform vec4 _Terrain; 530 | 531 | varying vec3 v_Normal; 532 | varying vec3 v_UV; 533 | 534 | vec3 CalNormal(float nTexU, float nTexV, vec4 mLngLat, vec4 mTerrain) 535 | { 536 | float aHeight[4]; 537 | vec4 aUV[4]; 538 | 539 | aUV[0] = vec4(nTexU - mLngLat.w, nTexV, 0.0, 0.0); 540 | aUV[1] = vec4(nTexU + mLngLat.w, nTexV, 0.0, 0.0); 541 | aUV[2] = vec4(nTexU, nTexV - mLngLat.w, 0.0, 0.0); 542 | aUV[3] = vec4(nTexU, nTexV + mLngLat.w, 0.0, 0.0); 543 | 544 | aHeight[0] = 0.0; 545 | aHeight[1] = 0.0; 546 | aHeight[2] = 0.0; 547 | aHeight[3] = 0.0; 548 | 549 | for (int i = 0; i < 4; i++) 550 | { 551 | // 约束到[0,1]范围 552 | aUV[i].xy /= mLngLat.z; 553 | aUV[i].x = aUV[i].x * mTerrain.z + mTerrain.x; 554 | aUV[i].y = aUV[i].y * mTerrain.z + mTerrain.y; 555 | 556 | vec4 mHeight = texture2D(_TerrainTex, aUV[i].xy); 557 | float nHeight = ((mHeight.r * 256.0 * 256.0 * 256.0) + (mHeight.g * 256.0 * 256.0) + (mHeight.b * 256.0)) * 0.001; 558 | 559 | aHeight[i] = nHeight - 1000.0; 560 | } 561 | 562 | float nLng = (mLngLat.x + nTexU) / 131072.0 * 3.141592654; 563 | float nLat = (mLngLat.y - nTexV) / 131072.0 * 3.141592654; 564 | 565 | vec3 mNormal = vec3(0.0, 1.0, 0.0); 566 | vec3 mBinormal = vec3(1.0, 0.0, 0.0); 567 | vec3 mTangent = vec3(0.0, 0.0, 1.0); 568 | 569 | float nScale = 1.0 / ((mLngLat.w / 131072.0 * 3.141592654) * 6378137.0); 570 | nScale *= 2.0; 571 | 572 | mNormal = mNormal + mBinormal * (aHeight[0] - aHeight[1]) * nScale + mTangent * (-aHeight[2] + aHeight[3]) * nScale; 573 | normalize(mNormal); 574 | 575 | return mNormal; 576 | } 577 | 578 | vec4 vs() 579 | { 580 | // 实例数据:左上角经度、左上角纬度、经纬度范围宽度、经纬度跨距。 581 | vec4 mLngLat = _LngLat; //a_Object; 582 | // 地形贴图偏移XY,地形贴图缩放Z,瓦片层级W。 583 | vec4 mTerrain = _Terrain;//a_MatW[0]; 584 | // 图像贴图偏移XY,未使用ZW 585 | vec4 mMap = vec4(0.0, 0.0, 0.0, 0.0);//a_MatW[1]; 586 | 587 | float nTexU = mLngLat.w * a_Position.x; 588 | float nTexV = mLngLat.w * a_Position.y; 589 | 590 | float nLng = (mLngLat.x + nTexU) / 131072.0 * 3.141592654; 591 | float nLat = (mLngLat.y - nTexV) / 131072.0 * 3.141592654; 592 | 593 | float nVecY = sin(nLat); 594 | float nVecX = cos(nLat) * cos(nLng); 595 | float nVecZ = cos(nLat) * sin(nLng); 596 | 597 | vec3 mPosition = normalize(vec3(nVecX, nVecY, nVecZ)); 598 | 599 | v_Normal = vec3(nVecX, nVecY, nVecZ); 600 | v_Normal = normalize((u_MatG * vec4(v_Normal, 0.0)).xyz); 601 | 602 | float nHeight = 0.0; 603 | if(7.9 < mTerrain.w) 604 | { 605 | vec2 _UV = vec2(nTexU, nTexV) / mLngLat.z; 606 | 607 | _UV.x = _UV.x * mTerrain.z + mTerrain.x; 608 | _UV.y = _UV.y * mTerrain.z + mTerrain.y; 609 | 610 | vec4 mHeight = texture2D(_TerrainTex, _UV); 611 | 612 | nHeight = ((mHeight.r * 256.0 * 256.0 * 256.0) + (mHeight.g * 256.0 * 256.0) + (mHeight.b * 256.0)) * 0.001; 613 | nHeight -= 991.0; 614 | 615 | // 高品质下,计算地形法线 616 | #ifdef HIGH_QUALITY 617 | v_Normal = CalNormal(nTexU, nTexV, mLngLat, mTerrain); 618 | #endif 619 | } 620 | 621 | mPosition = mPosition * (6378137.0 + nHeight); 622 | 623 | nTexU /= mLngLat.z; 624 | nTexV /= mLngLat.z; 625 | 626 | // 网格从左上角开始,影像贴图从左下角开始 627 | v_UV = vec3(nTexU, nTexV, mMap.y); 628 | 629 | // GIS的变换矩阵只包含旋转信息,未包含位移信息,避免精度不足造成画面抖动 630 | // return u_MatVP * u_MatG * vec4(mPosition.xyz, 1.0); 631 | 632 | vec4 mPosition_ = vec4(mPosition.xyz, 1.0); 633 | mPosition_ = u_MatG * mPosition_; 634 | mPosition_.y = mPosition_.y - 6378137.0; 635 | 636 | // 高品质下,计算大气散射 637 | #ifdef HIGH_QUALITY 638 | Atmosphere(normalize(u_Sunlight.xyz), mPosition_.xyz); 639 | #endif 640 | 641 | v_Object.a = 0.0; 642 | 643 | return u_MatVP * mPosition_; 644 | } 645 | `, 646 | fs_src: ` 647 | uniform sampler2D _TerrainTex; 648 | uniform sampler2D _PhotoTex; 649 | uniform sampler2D _LabelTex; 650 | 651 | uniform vec4 _Inherit; 652 | 653 | varying vec3 v_Normal; 654 | varying vec3 v_UV; 655 | 656 | vec4 fs() 657 | { 658 | vec2 mUV = vec2((v_UV.x * _Inherit.z + _Inherit.x), (v_UV.y * _Inherit.z + _Inherit.y)); 659 | vec4 mColor = texture(_PhotoTex, mUV) * 0.8; 660 | vec4 mLabel = texture(_LabelTex, mUV); 661 | 662 | mColor.rgb = (mColor.rgb * (1.0 - mLabel.a)) + (mLabel.rgb * mLabel.a); 663 | mColor.a = 1.0; 664 | 665 | // 高品质下,计算BRDF光照,计算大气散射 666 | #ifdef HIGH_QUALITY 667 | mColor.rgb += BRDF(normalize(u_Sunlight.xyz), normalize(v_ViewDir.xyz), v_Normal, vec3(0.0, 0.0, 1.0), vec3(1.0, 0.0, 0.0)) * 0.4; 668 | 669 | mColor = AtmosphereLight(mColor, normalize(u_Sunlight.xyz)); 670 | mColor.a = 1.0; 671 | #endif 672 | 673 | return mColor; 674 | } 675 | ` 676 | }; 677 | 678 | MiaokitJS.Shader["Panoramas"] = { 679 | name: "Panoramas", 680 | type: "Clear", 681 | mark: ["Opaque"], 682 | vs_src: ` 683 | // X:瓦片缩放、Y:子投影面索引、Z:绕Y轴逆时针旋转弧度、W:绕X轴逆时针旋转弧度 684 | uniform vec4 u_LngLat; 685 | uniform vec4 u_Position; 686 | uniform vec4 u_Desc; 687 | varying vec4 v_UV; 688 | 689 | vec4 vs() 690 | { 691 | // 中心投影法:设定球心位于原点处,令124*124的正方形立于X=62处,球心到正方形各个顶点的射线投影出一个弧面 692 | 693 | // 左上角基准点坐标,从左上角向右下角扫描 694 | vec4 mPosition = vec4(62.0, 62.0, -62.0, 4.0); 695 | 696 | // 投影面可以细分为16个子投影面,修改子投影面左上角基准点坐标 697 | mPosition.w *= u_LngLat.x; 698 | mPosition.z += 31.0 * mod(u_LngLat.y, 4.0); 699 | mPosition.y -= 31.0 * floor(u_LngLat.y / 4.0); 700 | 701 | // 当前投影点坐标 702 | mPosition.z += a_Position.x * mPosition.w; 703 | mPosition.y -= a_Position.y * mPosition.w; 704 | 705 | // 单位化投影射线 706 | mPosition.xyz = normalize(mPosition.xyz) * u_Desc.x; 707 | mPosition.w = 1.0; 708 | 709 | // 绕Y轴旋转 710 | float nCos = cos(u_LngLat.z); 711 | float nSin = sin(u_LngLat.z); 712 | float nX = mPosition.x; 713 | float nY = mPosition.y; 714 | float nZ = mPosition.z; 715 | mPosition.x = nX * nCos - nZ * nSin; 716 | mPosition.z = nX * nSin + nZ * nCos; 717 | 718 | // 绕X轴旋转 719 | nCos = cos(u_LngLat.w); 720 | nSin = sin(u_LngLat.w); 721 | nZ = mPosition.z; 722 | mPosition.y = nY * nCos - nZ * nSin; 723 | mPosition.z = nY * nSin + nZ * nCos; 724 | 725 | // 使指南针朝向正确 726 | nCos = cos(u_Desc.y); 727 | nSin = sin(u_Desc.y); 728 | nX = mPosition.x; 729 | nZ = mPosition.z; 730 | mPosition.x = nX * nCos - nZ * nSin; 731 | mPosition.z = nX * nSin + nZ * nCos; 732 | 733 | // 设置中心点位置 734 | mPosition.xyz += u_Position.xyz; 735 | 736 | // 纹理映射坐标 737 | v_UV = vec4(a_Position.xy / 31.0, 0.0, 0.0); 738 | 739 | return u_MatVP * mPosition; 740 | } 741 | `, 742 | fs_src: ` 743 | varying vec4 v_UV; 744 | 745 | vec4 fs() 746 | { 747 | vec4 mColor = texture(u_MainTex, vec2(1.0 - v_UV.x, v_UV.y)); 748 | mColor.a = 1.0; 749 | 750 | return mColor; 751 | } 752 | ` 753 | }; 754 | 755 | MiaokitJS.Shader["RoomPanor"] = { 756 | name: "RoomPanor", 757 | type: "Clear", 758 | mark: ["Opaque"], 759 | uniform_values: [["u_MainTex", 1]], 760 | vs_src: ` 761 | varying vec3 v_Position; 762 | varying vec3 v_Center; 763 | 764 | vec4 vs() 765 | { 766 | vec4 mPosition = vec4(a_Position.xyz, 1.0); 767 | mPosition = u_MatG * a_MatW * mPosition; 768 | 769 | v_Position = mPosition.xyz; 770 | v_Center = (u_MatG * a_MatW * vec4(-37.9, 1.5, 3.65, 1.0)).xyz; 771 | 772 | return u_MatVP * mPosition; 773 | } 774 | `, 775 | fs_src: ` 776 | varying vec3 v_Position; 777 | varying vec3 v_Center; 778 | 779 | vec4 fs() 780 | { 781 | // 这里u_EyePos是世界空间坐标 782 | vec3 _Eye = u_EyePos.xyz; 783 | vec3 _Ray = normalize(_Eye - v_Position); 784 | vec3 _LineC = v_Center - v_Position; 785 | 786 | float _LenProj = dot(_LineC, _Ray); 787 | float _LenC = length(_LineC); 788 | float _Dist = _LenC * _LenC - _LenProj * _LenProj; 789 | float _R = 1.5; 790 | 791 | vec3 _ProjC = v_Position + _Ray * _LenProj; 792 | 793 | _LenProj = sqrt(_R * _R - _Dist); 794 | _ProjC = _ProjC - _Ray * _LenProj; 795 | 796 | vec3 mView = _ProjC - v_Center; 797 | 798 | ///////////////////////////////////////////////////////// 799 | 800 | //vec3 mView = normalize(v_Position - v_Center); 801 | 802 | float nLength = length(mView); 803 | float nLat = asin(mView.y / nLength); 804 | float nLengthXZ = cos(nLat) * nLength; 805 | float nLng = acos(mView.x / nLengthXZ); 806 | 807 | if(0.0 > mView.z) 808 | { 809 | nLng = 6.283185308 - nLng; 810 | } 811 | 812 | float x = nLng / 6.283185308; 813 | float y = 1.0 - ((nLat + 1.570796327) / 3.141592654); 814 | 815 | vec4 mColor = texture(u_MainTex, vec2(x, y)); 816 | mColor.a = 1.0; 817 | 818 | return mColor; 819 | } 820 | ` 821 | }; 822 | 823 | MiaokitJS.Shader["Cosmos"] = { 824 | name: "Cosmos", 825 | type: "Clear", 826 | mark: ["Opaque"], 827 | uniform_values: [["u_MainTex", 1]], 828 | vs_src: PNT_SPHERE + ` 829 | vec4 vs() 830 | { 831 | return SPHERE(64.0); 832 | } 833 | `, 834 | fs_src: ` 835 | varying vec4 v_UV; 836 | 837 | vec4 fs() 838 | { 839 | vec4 mColor = Tex2D(u_MainTex, v_UV.xy); 840 | mColor.a = 1.0; 841 | 842 | return mColor; 843 | } 844 | ` 845 | }; 846 | 847 | MiaokitJS.Shader["Sky"] = { 848 | name: "Sky", 849 | type: "Clear", 850 | mark: ["Opaque"], 851 | include: [ 852 | ["ATOM"], 853 | ["ATOM"], 854 | ["ATOM"], 855 | ], 856 | vs_src: PNT_SPHERE + ` 857 | vec4 vs() 858 | { 859 | vec4 mClip = SPHERE(64.0); 860 | 861 | Atmosphere(normalize(u_Sunlight.xyz), v_Position.xyz); 862 | 863 | return mClip; 864 | } 865 | `, 866 | fs_src: ` 867 | vec4 fs() 868 | { 869 | return AtmosphereColor(vec4(1.0, 1.0, 1.0, 1.0), normalize(u_Sunlight.xyz)); 870 | } 871 | ` 872 | }; 873 | 874 | MiaokitJS.Shader["Ground"] = { 875 | name: "Ground", 876 | type: "Clear", 877 | mark: ["Opaque"], 878 | vs_src: PNT_SPHERE + ` 879 | vec4 vs() 880 | { 881 | return SPHERE(64.0); 882 | } 883 | `, 884 | fs_src: ` 885 | vec4 fs() 886 | { 887 | return vec4(0.1019608, 0.2862745, 0.3254902, 1.0); 888 | } 889 | ` 890 | }; 891 | 892 | MiaokitJS.Shader["Combine"] = { 893 | name: "Present", 894 | type: "Postprocess", 895 | mark: ["Opaque"], 896 | vs_src: ` 897 | varying vec2 v_UV; 898 | 899 | vec4 vs() 900 | { 901 | v_UV = a_UV; 902 | v_UV.y = 1.0 - v_UV.y; 903 | 904 | return vec4(a_Position, 1.0); 905 | } 906 | `, 907 | fs_src: ` 908 | uniform sampler2D u_MinorTex; 909 | 910 | varying vec2 v_UV; 911 | 912 | vec4 fs() 913 | { 914 | vec4 mColor = vec4(0.0, 0.0, 0.0, 0.0); 915 | vec4 mColor1 = texture2D(u_MainTex, v_UV); 916 | vec4 mColor2 = texture2D(u_MinorTex, v_UV); 917 | float nGray2 = mColor2.g / clamp(mColor2.b, 0.001, 50000.0); 918 | 919 | mColor.rgb = mColor1.rgb * mColor2.a + vec3(nGray2, nGray2, nGray2) * (1.0 - mColor2.a); 920 | mColor.a = mColor1.a + mColor2.r; 921 | 922 | // 标识是否高亮,边缘提取时不应再除以混合次数 923 | mColor.a = ceil(ceil(mColor.a) - mColor.a); 924 | 925 | // 低品质下,合成颜色直接输出,叠加高亮区域颜色 926 | #ifdef LOW_QUALITY 927 | mColor.rgb *= vec3(0.2, 0.4, 0.6) + (vec3(0.8, 0.6, 0.4) * (1.0 - mColor.a)); 928 | #endif 929 | 930 | return mColor; 931 | } 932 | ` 933 | }; 934 | 935 | MiaokitJS.Shader["EdgeDetection"] = { 936 | name: "EdgeDetection", 937 | type: "Postprocess", 938 | mark: ["Opaque"], 939 | vs_src: ` 940 | varying vec2 v_UV; 941 | 942 | vec4 vs() 943 | { 944 | v_UV = a_UV; 945 | v_UV.y = 1.0 - v_UV.y; 946 | 947 | return vec4(a_Position, 1.0); 948 | } 949 | `, 950 | fs_src: ` 951 | uniform vec4 u_InvTexSize; 952 | varying vec2 v_UV; 953 | 954 | #define FXAA_REDUCE_MIN (1.0/ 128.0) 955 | #define FXAA_REDUCE_MUL (1.0 / 8.0) 956 | #define FXAA_SPAN_MAX 8.0 957 | 958 | vec4 fs() 959 | { 960 | vec4 _OffsetUV = vec4(-1.0, 1.0, 1.0, 1.0) * vec4(u_InvTexSize.xy, u_InvTexSize.xy); 961 | 962 | /// 采样中心及周边斜角4个点的颜色================================ 963 | vec4 _Color0 = texture2D(u_MainTex, v_UV); 964 | vec4 _Color1 = texture2D(u_MainTex, v_UV + _OffsetUV.xy); // NW 965 | vec4 _Color2 = texture2D(u_MainTex, v_UV - _OffsetUV.xy); // SE 966 | vec4 _Color3 = texture2D(u_MainTex, v_UV + _OffsetUV.zw); // NE 967 | vec4 _Color4 = texture2D(u_MainTex, v_UV - _OffsetUV.zw); // SW 968 | 969 | /// 计算中心及周边斜角4个点的颜色灰度============================ 970 | vec3 _Luma = vec3(0.299, 0.587, 0.114); 971 | 972 | float _LumaM = dot(_Color0.rgb, _Luma); 973 | float _LumaNW = dot(_Color1.rgb, _Luma); 974 | float _LumaNE = dot(_Color3.rgb, _Luma); 975 | float _LumaSW = dot(_Color4.rgb, _Luma); 976 | float _LumaSE = dot(_Color2.rgb, _Luma); 977 | 978 | float _LumaMin = min(_LumaM, min(min(_LumaNW, _LumaNE), min(_LumaSW, _LumaSE))); 979 | float _LumaMax = max(_LumaM, max(max(_LumaNW, _LumaNE), max(_LumaSW, _LumaSE))); 980 | 981 | ///计算选中对象轮廓============================================== 982 | float _Diff1 = (_Color1.a - _Color2.a) * 0.5; 983 | float _Diff2 = (_Color3.a - _Color4.a) * 0.5; 984 | float _Diff = length(vec2(_Diff1, _Diff2)); 985 | 986 | ///FXAA处理====================================================== 987 | vec2 _Dir = vec2(-((_LumaNW + _LumaNE) - (_LumaSW + _LumaSE)), ((_LumaNW + _LumaSW) - (_LumaNE + _LumaSE))); 988 | 989 | float _DirReduce = max((_LumaNW + _LumaNE + _LumaSW + _LumaSE) * (0.25 * FXAA_REDUCE_MUL), FXAA_REDUCE_MIN); 990 | float _RcpDirMin = 1.0 / (min(abs(_Dir.x), abs(_Dir.y)) + _DirReduce); 991 | 992 | _Dir = min(vec2(FXAA_SPAN_MAX, FXAA_SPAN_MAX), max(vec2(-FXAA_SPAN_MAX, -FXAA_SPAN_MAX), _Dir * _RcpDirMin)) * u_InvTexSize.xy; 993 | 994 | vec4 _Blend0 = texture2D(u_MainTex, v_UV + _Dir * (1.0 / 3.0 - 0.5)); 995 | vec4 _Blend1 = texture2D(u_MainTex, v_UV + _Dir * (2.0 / 3.0 - 0.5)); 996 | vec4 _Blend2 = texture2D(u_MainTex, v_UV + _Dir * -0.5); 997 | vec4 _Blend3 = texture2D(u_MainTex, v_UV + _Dir * 0.5); 998 | 999 | vec3 _ColorA = vec3(0.0, 0.0, 0.0); 1000 | _ColorA += _Blend0.rgb; 1001 | _ColorA += _Blend1.rgb; 1002 | _ColorA *= 0.5; 1003 | 1004 | vec3 _ColorB = vec3(0.0, 0.0, 0.0); 1005 | _ColorB += _Blend2.rgb; 1006 | _ColorB += _Blend3.rgb; 1007 | _ColorB *= 0.25; 1008 | _ColorB += 0.5 * _ColorA; 1009 | 1010 | float _LumaB = dot(_ColorB, _Luma); 1011 | if ((_LumaB < _LumaMin) || (_LumaB > _LumaMax)) 1012 | { 1013 | _Color0.rgb = _ColorA; 1014 | } 1015 | else 1016 | { 1017 | _Color0.rgb = _ColorB; 1018 | } 1019 | ///计算素描线条================================================== 1020 | _Color0.a = _LumaM / (_LumaMax - _LumaMin); 1021 | ///叠加选中对象轮廓============================================== 1022 | _Color0.rgb += vec3(3.0, 0.5, 0.0) * _Diff; 1023 | 1024 | return _Color0; 1025 | } 1026 | ` 1027 | }; 1028 | 1029 | MiaokitJS.Shader["HDR"] = { 1030 | name: "HDR", 1031 | type: "Postprocess", 1032 | mark: ["Opaque"], 1033 | vs_src: ` 1034 | varying vec2 v_UV; 1035 | 1036 | vec4 vs() 1037 | { 1038 | v_UV = a_UV; 1039 | v_UV.y = 1.0 - v_UV.y; 1040 | 1041 | return vec4(a_Position, 1.0); 1042 | } 1043 | `, 1044 | fs_src: ` 1045 | varying vec2 v_UV; 1046 | 1047 | vec4 fs() 1048 | { 1049 | vec4 mColor = texture2D(u_MainTex, v_UV); 1050 | 1051 | // https://catlikecoding.com/unity/tutorials/advanced-rendering/bloom/ 1052 | // 高光阈值。阈值为1时,LDR没有光晕 1053 | float nThreshold = 1.0; 1054 | // 软过渡阈值[0, 1.0],值为0时,在亮度为1处硬过渡,值为1时,亮度从0开始平滑过渡 1055 | float nSoftThreshold = 0.5; 1056 | // 使用彩色最大组成部分代表它的亮度 1057 | float nBrightness = max(mColor.r, max(mColor.r, mColor.b)); 1058 | // 低于高光阈值的部分,给予一个非0的共享,避免硬过渡 1059 | float nSoft = 0.0; 1060 | { 1061 | float nKnee = nThreshold * nSoftThreshold; 1062 | nSoft = nBrightness - nThreshold + nKnee; 1063 | nSoft = clamp(nSoft, 0.0, 2.0 * nKnee); 1064 | nSoft = nSoft * nSoft / (4.0 * nKnee + 0.00001); 1065 | } 1066 | // 贡献因子=亮度-阈值/亮度 1067 | float nContrib = max(nSoft, nBrightness - nThreshold); 1068 | nContrib /= max(nBrightness, 0.00001); 1069 | 1070 | return mColor * nContrib; 1071 | } 1072 | ` 1073 | }; 1074 | 1075 | MiaokitJS.Shader["Upsampling"] = { 1076 | name: "Upsampling", 1077 | type: "Postprocess", 1078 | mark: ["Opaque"], 1079 | vs_src: ` 1080 | varying vec2 v_UV; 1081 | 1082 | vec4 vs() 1083 | { 1084 | v_UV = a_UV; 1085 | v_UV.y = 1.0 - v_UV.y; 1086 | 1087 | return vec4(a_Position, 1.0); 1088 | } 1089 | `, 1090 | fs_src: ` 1091 | //[1.0/W, 1.0/H, LOD, 0] 1092 | uniform vec4 u_InvTexSize; 1093 | uniform sampler2D u_MinorTex; 1094 | 1095 | varying vec2 v_UV; 1096 | 1097 | vec4 fs() 1098 | { 1099 | vec4 mColor = vec4(0.0, 0.0, 0.0, 0.0); 1100 | vec4 mBias = vec4(-u_InvTexSize.x, u_InvTexSize.y, u_InvTexSize.x, u_InvTexSize.y); 1101 | 1102 | mColor += texture2D(u_MinorTex, v_UV + mBias.xy, u_InvTexSize.z); 1103 | mColor += texture2D(u_MinorTex, v_UV - mBias.xy, u_InvTexSize.z); 1104 | mColor += texture2D(u_MinorTex, v_UV + mBias.zw, u_InvTexSize.z); 1105 | mColor += texture2D(u_MinorTex, v_UV - mBias.zw, u_InvTexSize.z); 1106 | mColor *= 0.25; 1107 | 1108 | mColor += texture2D(u_MainTex, v_UV, u_InvTexSize.w); 1109 | 1110 | return mColor; 1111 | } 1112 | ` 1113 | }; 1114 | 1115 | MiaokitJS.Shader["Present"] = { 1116 | name: "Present", 1117 | type: "Postprocess", 1118 | mark: ["Opaque"], 1119 | vs_src: ` 1120 | varying vec2 v_UV; 1121 | 1122 | vec4 vs() 1123 | { 1124 | v_UV = a_UV; 1125 | v_UV.y = 1.0 - v_UV.y; 1126 | 1127 | return vec4(a_Position, 1.0); 1128 | } 1129 | `, 1130 | fs_src: ` 1131 | uniform sampler2D u_MinorTex; 1132 | 1133 | varying vec2 v_UV; 1134 | 1135 | vec4 fs() 1136 | { 1137 | vec4 mColor = texture2D(u_MainTex, v_UV); 1138 | vec4 mBloom = texture2D(u_MinorTex, v_UV); 1139 | 1140 | mColor += mBloom; 1141 | 1142 | return mColor; 1143 | } 1144 | ` 1145 | }; 1146 | -------------------------------------------------------------------------------- /web/private/common/util/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compileOnSave": true, 3 | "compilerOptions": { 4 | "module": "system", 5 | "outDir": "../../../public/common", 6 | "outFile": "../../../public/common/util.js", 7 | "noImplicitAny": false, 8 | "noEmitOnError": true, 9 | "removeComments": true, 10 | "sourceMap": false, 11 | "target": "es6" 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /web/public/common/miaokit/Miaokit.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/common/miaokit/Miaokit.wasm -------------------------------------------------------------------------------- /web/public/common/miaokit/MiaokitWorker.min.js: -------------------------------------------------------------------------------- 1 | var pWorker = (function (pEnv) { 2 | var m_pPost = pEnv.postMessage; 3 | var m_aWait = []; 4 | var m_pLoadMapbox = MapboxLoader(); 5 | var pTextDecoder = new TextDecoder('utf-8'); 6 | var m_nStartTime = Date.now(); 7 | var m_pMemory = new WebAssembly.Memory({ initial: 64 * 16, maximum: 32768 }); 8 | var m_pHeap = { 9 | WriteArrayBuffer: function (nAddr, pData) { 10 | this.m_pU8.set(new Uint8Array(pData), nAddr); 11 | }, 12 | WriteFloat32Array: function (nAddr, aData) { 13 | this.m_pF32.set(aData, nAddr / 4); 14 | }, 15 | ReadU32: function (nAddr, nCount) { 16 | return this.m_pU32.subarray(nAddr / 4, nAddr / 4 + nCount); 17 | }, 18 | SliceU8: function (nAddr, nCount) { 19 | return this.m_pU8.slice(nAddr, nAddr + nCount); 20 | }, 21 | m_pU8: new Uint8Array(m_pMemory.buffer), 22 | m_pU32: new Uint32Array(m_pMemory.buffer), 23 | m_pF32: new Float32Array(m_pMemory.buffer) 24 | }; 25 | var m_aFuncLut = null; 26 | var m_pFunc = { 27 | env: { 28 | "memory": m_pMemory, 29 | "APP_PLUGIN_TYPE": function () { 30 | return 2; 31 | }, 32 | "APP_MEM_TYPE": function () { 33 | return 1; 34 | }, 35 | "APP_MEM_RESERVE": function () { 36 | return 1024; 37 | }, 38 | "APP_MEM_BASE": function () { 39 | console.error("子线程不支持使用线性内存!"); 40 | return 0; 41 | }, 42 | "APP_MEM_GROW": function (nSize) { 43 | console.error("子线程不支持使用线性内存!"); 44 | }, 45 | "APP_MEM_RECYCLE": function (nSize) { 46 | console.error("子线程不支持使用线性内存!"); 47 | }, 48 | "APP_MEM_MALLOC": function (nSize) { 49 | console.error("子线程仅允许使用60M内存!"); 50 | return 0; 51 | }, 52 | "APP_MEM_FREE": function (nPtr) { 53 | console.error("子线程不允许回收固定内存!"); 54 | }, 55 | "APP_PRINT": function (nMsgAddr, nMsgSize, nCtrl) { 56 | var aChar = m_pHeap.m_pU8.subarray(nMsgAddr, nMsgAddr + nMsgSize); 57 | var pMsg = pTextDecoder.decode(aChar); 58 | if (2 === nCtrl) { 59 | console.warn("Worker:", (Date.now() - m_nStartTime), pMsg); 60 | } 61 | else if (2 < nCtrl) { 62 | console.error("Worker:", (Date.now() - m_nStartTime), pMsg); 63 | } 64 | else { 65 | console.info("Worker:", (Date.now() - m_nStartTime), pMsg); 66 | } 67 | } 68 | } 69 | }; 70 | pEnv.onmessage = function (pEvent) { 71 | var pData = pEvent.data; 72 | if (m_aWait) { 73 | if (1 === pData.m_nID) { 74 | Init(pData.m_aCode, function () { 75 | m_pPost({ 76 | m_nID: 1, 77 | m_aDict: ["1:INIT", "2:LOAD_TERRAIN", "3:LOAD_MAPBOX"] 78 | }); 79 | var aWait = m_aWait; 80 | m_aWait = null; 81 | for (var _i = 0, aWait_1 = aWait; _i < aWait_1.length; _i++) { 82 | var pEvent_ = aWait_1[_i]; 83 | pEnv.onmessage(pEvent_); 84 | } 85 | }); 86 | return; 87 | } 88 | m_aWait.push(pEvent); 89 | return; 90 | } 91 | switch (pData.m_nID) { 92 | case 2: 93 | LoadTerrain(pData); 94 | break; 95 | case 3: 96 | m_pLoadMapbox(pData); 97 | break; 98 | case 4: 99 | Load3MX(pData); 100 | break; 101 | default: 102 | console.error("主线程消息异常:", pData); 103 | break; 104 | } 105 | }; 106 | function Load3MX(pEvent) { 107 | var pPath = pEvent.m_pPath; 108 | var pPath_ = pPath; 109 | var nNewFolder = pEvent.m_nNewFolder; 110 | if (!pPath_.startsWith("http")) { 111 | pPath_ = "../../" + pPath_; 112 | } 113 | Fetch(pPath_, function (aData) { 114 | if (!aData) { 115 | return; 116 | } 117 | var aMeta = new Uint32Array(aData, 0, 2); 118 | if (0x42584D33 === aMeta[0]) { 119 | var nHeaderSize = aMeta[1] >> 8; 120 | var nDataAddr = 9 + nHeaderSize; 121 | var nDataSize = aData.byteLength - nDataAddr; 122 | var aHeader = new Uint8Array(aData, 9, nHeaderSize); 123 | var pHeader = pTextDecoder.decode(aHeader); 124 | var jHeader = JSON.parse(pHeader); 125 | var pFolder = { 126 | m_pPath: pPath.substring(0, (pPath.lastIndexOf("/") + 1)), 127 | m_aFile: [] 128 | }; 129 | var tRes = []; 130 | var oRes = []; 131 | var iRes = jHeader.resources; 132 | var nOffset = 0; 133 | for (var i = 0; i < iRes.length; i++) { 134 | tRes.push(i); 135 | if ("textureBuffer" === iRes[i].type) { 136 | tRes.push(0); 137 | oRes.push(i); 138 | if ("jpg" === iRes[i].format) { 139 | tRes.push(0); 140 | } 141 | else if ("png" === iRes[i].format) { 142 | tRes.push(1); 143 | } 144 | else { 145 | tRes.push(10000); 146 | } 147 | } 148 | else if ("geometryBuffer" === iRes[i].type) { 149 | tRes.push(1); 150 | if ("ctm" === iRes[i].format) { 151 | tRes.push(0); 152 | } 153 | else { 154 | tRes.push(10000); 155 | } 156 | } 157 | else { 158 | tRes.push(10000); 159 | tRes.push(10000); 160 | } 161 | tRes.push(iRes[i].size); 162 | tRes.push(nOffset); 163 | nOffset += iRes[i].size; 164 | tRes.push(10000); 165 | if (iRes[i].texture) { 166 | for (var j = 0; j < iRes.length; j++) { 167 | if (iRes[i].texture === iRes[j].id) { 168 | tRes[tRes.length - 1] = j; 169 | break; 170 | } 171 | } 172 | } 173 | } 174 | var oNode = []; 175 | var iNode = jHeader.nodes; 176 | for (var i = 0; i < iNode.length; i++) { 177 | var pNode = iNode[i]; 178 | var xLen = pNode.bbMax[0] - pNode.bbMin[0]; 179 | var yLen = pNode.bbMax[1] - pNode.bbMin[1]; 180 | var zLen = pNode.bbMax[2] - pNode.bbMin[2]; 181 | var nLen = Math.sqrt(xLen * xLen + yLen * yLen + zLen * zLen); 182 | oNode.push(Math.floor(parseInt(pNode.bbMin[0] + pNode.bbMax[0]) * 0.5 * 100.0)); 183 | oNode.push(Math.floor(parseInt(pNode.bbMin[1] + pNode.bbMax[1]) * 0.5 * 100.0)); 184 | oNode.push(Math.floor(parseInt(pNode.bbMin[2] + pNode.bbMax[2]) * 0.5 * 100.0)); 185 | oNode.push(Math.floor(nLen * 100.0) * 1024 + zLen); 186 | oNode.push(Math.floor(pNode.maxScreenDiameter)); 187 | var nSubCount = pNode.children ? pNode.children.length : 0; 188 | if (0 < nSubCount) { 189 | oNode.push(pFolder.m_aFile.length); 190 | for (var j = 0; j < nSubCount; j++) { 191 | pFolder.m_aFile.push(pNode.children[j]); 192 | } 193 | oNode.push(pFolder.m_aFile.length); 194 | } 195 | else { 196 | oNode.push(-1); 197 | oNode.push(-1); 198 | } 199 | var nResCount = pNode.resources ? pNode.resources.length : 0; 200 | if (0 < nResCount) { 201 | oNode.push(oRes.length); 202 | for (var j = 0; j < nResCount; j++) { 203 | for (var k = 0; k < iRes.length; k++) { 204 | if (pNode.resources[j] === iRes[k].id) { 205 | oRes.push(k); 206 | break; 207 | } 208 | } 209 | } 210 | oNode.push(oRes.length); 211 | } 212 | else { 213 | oNode.push(-1); 214 | oNode.push(-1); 215 | } 216 | } 217 | var nDescNum = 4 + (9 * iNode.length) + (6 * oRes.length); 218 | var nDescSize = 4 * nDescNum; 219 | var oDesc = new Int32Array(nDescNum); 220 | var oData = [oDesc.buffer]; 221 | { 222 | oDesc[0] = nDescSize; 223 | oDesc[1] = iNode.length; 224 | oDesc[2] = oRes.length; 225 | oDesc[3] = nNewFolder; 226 | oDesc.set(oNode, 4); 227 | var nIndex = 4 + oNode.length; 228 | for (var i = 0; i < oRes.length; i++) { 229 | var nIndex2 = 6 * oRes[i]; 230 | for (var j = 0; j < 6; j++) { 231 | oDesc[nIndex++] = tRes[nIndex2++]; 232 | } 233 | var nIndex3 = nIndex - 6; 234 | { 235 | var nType_ = oDesc[nIndex3 + 1]; 236 | var nAddr_ = nDataAddr + oDesc[nIndex3 + 4]; 237 | var nSize_ = oDesc[nIndex3 + 3]; 238 | var pData_ = aData.slice(nAddr_, nAddr_ + nSize_); 239 | if (0 === nType_) { 240 | oData.push(pData_); 241 | } 242 | else if (1 === nType_) { 243 | var nBufferAddr = m_pFunc.UTIL_BUFFER(nSize_); 244 | m_pHeap.WriteArrayBuffer(nBufferAddr, pData_); 245 | nBufferAddr = m_pFunc.UTIL_DECODE_CTM(nBufferAddr, nSize_); 246 | if (0 < nBufferAddr) { 247 | var aRef = m_pHeap.ReadU32(nBufferAddr, 2); 248 | pData_ = m_pMemory.buffer.slice(aRef[0], aRef[0] + aRef[1]); 249 | oData.push(pData_); 250 | } 251 | else { 252 | oData.push(null); 253 | } 254 | } 255 | else { 256 | oData.push(null); 257 | } 258 | } 259 | } 260 | } 261 | pEvent.m_pNewFolder = pFolder; 262 | pEvent.m_pData = oData; 263 | m_pPost(pEvent, oData); 264 | } 265 | }); 266 | } 267 | function LoadTerrain(pEvent) { 268 | Fetch(pEvent.m_pPath, function (pData) { 269 | if (!pData || 152 === pData.byteLength) { 270 | pEvent.m_pData = null; 271 | m_pPost(pEvent); 272 | return; 273 | } 274 | var nSize = pData.byteLength; 275 | var nAddr = m_pFunc.UTIL_BUFFER(nSize); 276 | var aOut = null; 277 | if (0 < nAddr) { 278 | m_pHeap.WriteArrayBuffer(nAddr, pData); 279 | nAddr = m_pFunc.UTIL_DECODE_TERRAIN(nAddr, nSize); 280 | if (0 < nAddr) { 281 | var aRef = m_pHeap.ReadU32(nAddr, 2); 282 | aOut = m_pHeap.SliceU8(aRef[0], aRef[1]).buffer; 283 | } 284 | } 285 | if (aOut) { 286 | pEvent.m_pData = aOut; 287 | m_pPost(pEvent, [aOut]); 288 | } 289 | else { 290 | pEvent.m_pData = null; 291 | m_pPost(pEvent); 292 | } 293 | }); 294 | } 295 | function MapboxLoader() { 296 | var LoadMapboxTile = Mapbox(); 297 | var aQueue = []; 298 | var bDoing = false; 299 | var LoadMapboxEnd = function (nDesc) { 300 | var pEvent = aQueue.shift(); 301 | var aTransfer = []; 302 | var aOut = []; 303 | var aDesc = m_pHeap.ReadU32(nDesc, 28); 304 | for (var i = 0; i < 4; i++) { 305 | var nIndex = 7 * i; 306 | var pMesh = { 307 | m_nVertexCount: aDesc[nIndex + 0], 308 | m_nInputCount: aDesc[nIndex + 1], 309 | m_nSubmeshCount: aDesc[nIndex + 2], 310 | m_aPosition: null, 311 | m_aNormal: null, 312 | m_aUV: null, 313 | m_aIndex: null 314 | }; 315 | if (0 < pMesh.m_nVertexCount && 0 < pMesh.m_nSubmeshCount) { 316 | pMesh.m_aPosition = m_pHeap.SliceU8(aDesc[nIndex + 3], 12 * pMesh.m_nVertexCount).buffer; 317 | pMesh.m_aNormal = m_pHeap.SliceU8(aDesc[nIndex + 4], 12 * pMesh.m_nVertexCount).buffer; 318 | pMesh.m_aUV = m_pHeap.SliceU8(aDesc[nIndex + 5], 8 * pMesh.m_nVertexCount).buffer; 319 | pMesh.m_aIndex = m_pHeap.SliceU8(aDesc[nIndex + 6], 8 * pMesh.m_nSubmeshCount).buffer; 320 | aTransfer.push(pMesh.m_aPosition); 321 | aTransfer.push(pMesh.m_aNormal); 322 | aTransfer.push(pMesh.m_aUV); 323 | aTransfer.push(pMesh.m_aIndex); 324 | } 325 | aOut.push(pMesh); 326 | } 327 | pEvent.m_pData = aOut; 328 | m_pPost(pEvent, aTransfer); 329 | bDoing = false; 330 | }; 331 | var LoadBlockbox = function (nCol, nRow, nColOffset, nRowOffset) { 332 | m_pFunc.UTIL_DECODE_MAPBOX_BLOCK_START(16); 333 | var _loop_1 = function (i) { 334 | var _loop_2 = function (j) { 335 | LoadMapboxTile(nCol + j, nRow + i, 18, function (pData) { 336 | var nAddr = 0; 337 | var nCount = 0; 338 | if (pData) { 339 | var nSize = 4 * pData.m_aData.length; 340 | nAddr = m_pFunc.UTIL_BUFFER(nSize); 341 | if (nAddr) { 342 | m_pHeap.WriteFloat32Array(nAddr, pData.m_aData); 343 | nCount = pData.m_nCount; 344 | } 345 | } 346 | var nBlock = m_pFunc.UTIL_DECODE_MAPBOX_BLOCK_FILL(nColOffset, nRowOffset, 4 * i + j, nCount, nAddr); 347 | if (nBlock) { 348 | LoadMapboxEnd(nBlock); 349 | } 350 | }); 351 | }; 352 | for (var j = 0; j < 4; j++) { 353 | _loop_2(j); 354 | } 355 | }; 356 | for (var i = 0; i < 4; i++) { 357 | _loop_1(i); 358 | } 359 | }; 360 | return function (pEvent) { 361 | aQueue.push(pEvent); 362 | if (!bDoing) { 363 | bDoing = true; 364 | pEvent = aQueue[0]; 365 | LoadBlockbox(pEvent.m_nCol, pEvent.m_nRow, pEvent.m_nColOffset, pEvent.m_nRowOffset); 366 | } 367 | }; 368 | } 369 | function Fetch(pPath, pCallback) { 370 | fetch(pPath) 371 | .then(function (pResponse) { return pResponse.arrayBuffer(); }) 372 | .then(function (pBuffer) { 373 | if (null !== pBuffer) { 374 | pCallback(pBuffer); 375 | } 376 | else { 377 | console.error("Fetch null: ", pPath); 378 | pCallback(null); 379 | } 380 | }).catch(function (e) { 381 | console.error("Fetch error: ", pPath, e); 382 | }); 383 | } 384 | function Init(pBlob, pCallback) { 385 | WebAssembly.instantiate(pBlob, m_pFunc) 386 | .then(function (pModule_) { return pModule_.instance; }) 387 | .then(function (pInstance) { 388 | m_pFunc = pInstance.exports; 389 | m_aFuncLut = pInstance.exports.__indirect_function_table; 390 | pCallback(); 391 | }) 392 | .catch(function (e) { 393 | console.error("WebAssembly.instantiate error:", e); 394 | }); 395 | } 396 | })(this); 397 | function Mapbox() { 398 | var POLYGON_STYLE = 5; 399 | var POLYGON3D_STYLE = 6; 400 | var aServer = [ 401 | "https://ss0.bdstatic.com/8bo_dTSlR1gBo1vgoIiO_jowehsv", 402 | "https://ss1.bdstatic.com/8bo_dTSlR1gBo1vgoIiO_jowehsv", 403 | "https://ss2.bdstatic.com/8bo_dTSlR1gBo1vgoIiO_jowehsv", 404 | "https://ss3.bdstatic.com/8bo_dTSlR1gBo1vgoIiO_jowehsv" 405 | ]; 406 | var aOriginServer = ["https://pcor.baidu.com/"]; 407 | var pVersion = "001"; 408 | var pUdt = "20190919"; 409 | var nPixelRatio = 1; 410 | var pFeatureStyle = undefined; 411 | var pWaite = []; 412 | function Fetch(pPath, pCallback) { 413 | fetch(pPath) 414 | .then(function (pResponse) { return pResponse.text(); }) 415 | .then(function (pBuffer) { 416 | if (null !== pBuffer) { 417 | pCallback(pBuffer); 418 | } 419 | else { 420 | console.error("Fetch null: ", pPath); 421 | } 422 | }).catch(function (e) { 423 | console.error("Fetch error: ", pPath, e); 424 | }); 425 | } 426 | function LoadFS(pCallback) { 427 | var pUrl = aServer[0] + "/sty/vpl.js?udt=" + pUdt + "&v=" + pVersion; 428 | Fetch(pUrl, function (aData) { 429 | pFeatureStyle = eval(aData.substring(20)); 430 | pCallback(); 431 | }); 432 | } 433 | function LoadVectorTileData(nCol, nRow, nLevel, pCallback) { 434 | var pKey = GetTileKey(nCol, nRow, nLevel); 435 | var pUrl = GetTilesUrl(nCol, nRow, nLevel); 436 | if (!pFeatureStyle) { 437 | if (undefined === pFeatureStyle) { 438 | pFeatureStyle = null; 439 | LoadFS(function () { 440 | for (var _i = 0, pWaite_1 = pWaite; _i < pWaite_1.length; _i++) { 441 | var func = pWaite_1[_i]; 442 | func(); 443 | } 444 | }); 445 | } 446 | pWaite.push(function () { 447 | Fetch(pUrl, function (aData) { 448 | pCallback(pKey, aData); 449 | }); 450 | }); 451 | } 452 | else { 453 | Fetch(pUrl, function (aData) { 454 | pCallback(pKey, aData); 455 | }); 456 | } 457 | } 458 | function GetTileKey(nCol, nRow, nLevel) { 459 | return "B_NORMAL_MAP" + "_" + nCol + "_" + nRow + "_" + nLevel; 460 | } 461 | function GetTilesUrl(nCol_, nRow_, nLeve_) { 462 | var nCol = CalcLoopParam(nCol_, nLeve_); 463 | var nRow = nRow_; 464 | var nPath = Math.abs(nCol + nRow) % aServer.length; 465 | var pPath = aServer[nPath]; 466 | if (2 === Math.abs(nCol + nRow) % 3) { 467 | pPath = aOriginServer[0]; 468 | } 469 | var nLimit = (nLeve_ >= 3 && 9 >= nLeve_) ? 100 : 80; 470 | var pScaler = nPixelRatio > 1 ? "&scaler=2" : ""; 471 | var pParam = "x=" + nCol + "&y=" + nRow + "&z=" + nLeve_; 472 | pParam += "&styles=pl&p=0&cm=1&limit=" + nLimit + pScaler + "&udt=" + pUdt + "&v=" + pVersion; 473 | var pUrl = pPath + "/pvd/?qt=tile" + "¶m=" + EncodeUrl(pParam); 474 | return pUrl; 475 | } 476 | function CalcLoopParam(nCol, nLevel) { 477 | var nCount = 6 * Math.pow(2, nLevel - 3); 478 | var nStart = -nCount / 2; 479 | var nEnd = nCount / 2 - 1; 480 | for (; nCol > nEnd;) { 481 | nCol -= nCount; 482 | } 483 | for (; nStart > nCol;) { 484 | nCol += nCount; 485 | } 486 | return nCol; 487 | } 488 | function EncodeUrl(pUrl) { 489 | var pBinaryUrl = ""; 490 | for (var i = 0; i < pUrl.length; i++) { 491 | var nChar = pUrl.charCodeAt(i) << 1; 492 | var pBinary = nChar.toString(2); 493 | var pBinary8 = pBinary; 494 | if (8 > pBinary.length) { 495 | pBinary8 = "00000000" + pBinary; 496 | pBinary8 = pBinary8.substr(pBinary.length, 8); 497 | } 498 | pBinaryUrl += pBinary8; 499 | } 500 | var nGap = 5 - pBinaryUrl.length % 5; 501 | var pAppend = ""; 502 | for (var i = 0; i < nGap; i++) { 503 | pAppend += "0"; 504 | } 505 | pBinaryUrl = pAppend + pBinaryUrl; 506 | var pOut = ""; 507 | for (var i = 0; i < pBinaryUrl.length / 5; i++) { 508 | var pSubstring = pBinaryUrl.substr(5 * i, 5); 509 | var nCode = parseInt(pSubstring, 2) + 50; 510 | var nChar = String.fromCharCode(nCode); 511 | pOut += nChar; 512 | } 513 | return pOut + nGap; 514 | } 515 | function ParseData(pData, nLevel) { 516 | var jData = undefined; 517 | eval("jData = " + pData); 518 | return ParseRegion(jData, nLevel); 519 | } 520 | function ParseRegion(jData, nLevel) { 521 | var aData = []; 522 | var nCount = 0; 523 | var jRegionList = jData[2]; 524 | var jRoadList = jData[6]; 525 | if (jRegionList) { 526 | for (var i = 0; i < jRegionList.length; i++) { 527 | var jRegion = jRegionList[i]; 528 | var jFStyle = pFeatureStyle[jRegion[5]]; 529 | if (18 <= nLevel && POLYGON3D_STYLE === jFStyle[0]) { 530 | var pID = jRegion[1]; 531 | var nHeight = jRegion[3] * Math.pow(2, nLevel - 18); 532 | aData.push(0.0); 533 | aData.push(1.0); 534 | aData.push(1.0); 535 | aData.push(1.0); 536 | aData.push(1.0); 537 | aData.push(1.0); 538 | aData.push(nHeight); 539 | ParseFeature(jRegion, "Building", aData); 540 | nCount++; 541 | } 542 | else if (POLYGON_STYLE === jFStyle[0]) { 543 | if (jRegion[4] && "090301" === jRegion[4].toString()) { 544 | continue; 545 | } 546 | var pColor = jFStyle[1]; 547 | var aColor = pColor.split(','); 548 | aData.push(0.0); 549 | aData.push(2.0); 550 | aData.push(parseInt(aColor[0])); 551 | aData.push(parseInt(aColor[1])); 552 | aData.push(parseInt(aColor[2])); 553 | aData.push(parseInt(aColor[3])); 554 | aData.push(0.0); 555 | ParseFeature(jRegion, "Area", aData); 556 | nCount++; 557 | } 558 | } 559 | } 560 | if (jRoadList) { 561 | for (var i = 0; i < jRoadList.length; i++) { 562 | var jRegion = jRoadList[i]; 563 | var jFStyle = pFeatureStyle[jRegion[5]]; 564 | var pColor = jFStyle[1]; 565 | var aColor = pColor.split(','); 566 | aData.push(0.0); 567 | aData.push(3.0); 568 | aData.push(parseInt(aColor[0])); 569 | aData.push(parseInt(aColor[1])); 570 | aData.push(parseInt(aColor[2])); 571 | aData.push(parseInt(aColor[3])); 572 | aData.push(0.0); 573 | ParseFeature(jRegion, "Road", aData); 574 | nCount++; 575 | } 576 | } 577 | return { m_nCount: nCount, m_aData: aData }; 578 | } 579 | function ParseFeature(jRegion, pType, aData) { 580 | var jPolygon = jRegion[0]; 581 | var x = 0.0; 582 | var z = 0.0; 583 | aData.push(jPolygon.length); 584 | if ("Building" === pType) { 585 | for (var i = 0; i < jPolygon.length; i++) { 586 | x += jPolygon[i][0] / 10; 587 | z += jPolygon[i][1] / 10; 588 | aData.push(x); 589 | aData.push(0.0); 590 | aData.push(z); 591 | } 592 | } 593 | else if ("Area" === pType || "Road" === pType) { 594 | for (var i = 0; i < jPolygon.length; i++) { 595 | x += jPolygon[i][0] / 10; 596 | z += jPolygon[i][1] / 10; 597 | aData.push(x); 598 | aData.push(0.0); 599 | aData.push(z); 600 | } 601 | } 602 | } 603 | function LoadBdmapTile(nCol, nRow, nLevel, pCallback) { 604 | LoadVectorTileData(nCol, nRow, nLevel, function (pKey, pText) { 605 | if (pText) { 606 | var pData = ParseData(pText, nLevel); 607 | pCallback(pData); 608 | } 609 | else { 610 | pCallback(null); 611 | } 612 | }); 613 | } 614 | return LoadBdmapTile; 615 | } 616 | -------------------------------------------------------------------------------- /web/public/common/miaokit/MiaokitWorker.wasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/common/miaokit/MiaokitWorker.wasm -------------------------------------------------------------------------------- /web/public/data/projects/config.txt: -------------------------------------------------------------------------------- 1 | { 2 | "ID": "WWW.YONGTOC.COM", 3 | "AUTHORIZATION": "", 4 | "MODULE": "./common/miaokit/Miaokit.wasm", 5 | "UNITY": "./common/miaokit/MiaokitU3D/Build/MiaokitU3D.json", 6 | "SVE_SERVER": "http://base.oss.yongtoc.com/CommonModel/model/", 7 | "WEBGL": 2, 8 | "QUALITY": 0, 9 | "GIS": [ 10 | { 11 | "m_pImageServer": "http://t%d.tianditu.gov.cn/DataServer?T=img_c&tk=70c2460e14a978d29b759a7bb12d197a&x=%d&y=%d&l=%d", 12 | "m_pLabelServer": "http://t%d.tianditu.gov.cn/DataServer?T=cia_c&tk=70c2460e14a978d29b759a7bb12d197a&x=%d&y=%d&l=%d", 13 | "m_pTerrainServer": "https://t%d.tianditu.gov.cn/DEM/DataServer?T=ele_c&tk=70c2460e14a978d29b759a7bb12d197a&x=%d&y=%d&l=%d" 14 | }, 15 | { 16 | "m_pImageServer": "http://t%d.tianditu.gov.cn/DataServer?T=vec_c&tk=70c2460e14a978d29b759a7bb12d197a&x=%d&y=%d&l=%d", 17 | "m_pLabelServer": "http://t%d.tianditu.gov.cn/DataServer?T=cia_c&tk=70c2460e14a978d29b759a7bb12d197a&x=%d&y=%d&l=%d" 18 | } 19 | ], 20 | "MAPBOX":[ 21 | ] 22 | } -------------------------------------------------------------------------------- /web/public/data/projects/images/building.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/data/projects/images/building.png -------------------------------------------------------------------------------- /web/public/data/projects/images/bus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/data/projects/images/bus.png -------------------------------------------------------------------------------- /web/public/data/projects/images/business.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/data/projects/images/business.png -------------------------------------------------------------------------------- /web/public/data/projects/images/default.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/data/projects/images/default.png -------------------------------------------------------------------------------- /web/public/data/projects/images/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/data/projects/images/logo.png -------------------------------------------------------------------------------- /web/public/data/projects/images/panor.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/data/projects/images/panor.png -------------------------------------------------------------------------------- /web/public/data/projects/images/park.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/data/projects/images/park.png -------------------------------------------------------------------------------- /web/public/data/projects/images/star.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/data/projects/images/star.jpg -------------------------------------------------------------------------------- /web/public/data/tools/Exporter.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEngine; 5 | using UnityEditor; 6 | 7 | public class Exporter 8 | { 9 | // AB: https://blog.csdn.net/llj1985/article/details/51314384 10 | 11 | [MenuItem("GameObject/加载模型", false, 0)] 12 | static void Load() 13 | { 14 | string pFile = EditorUtility.OpenFilePanel("加载模型", m_pProjectPath, "assetbundle"); 15 | if (null != pFile && 0 < pFile.Length) 16 | { 17 | AssetBundle pAsset = AssetBundle.LoadFromFile(pFile); 18 | UnityEngine.Object pPrefab = pAsset.LoadAsset(pAsset.GetAllAssetNames()[0]); 19 | 20 | GameObject pObject = GameObject.Instantiate(pPrefab) as GameObject; 21 | 22 | pAsset.Unload(false); 23 | 24 | Debug.LogWarning("加载模型完成:" + pFile); 25 | } 26 | else 27 | { 28 | Debug.LogWarning("请选择一个文件!"); 29 | } 30 | } 31 | 32 | [MenuItem("GameObject/转换移动端资源包", false, 0)] 33 | static void Convert() 34 | { 35 | string pPath = EditorUtility.OpenFolderPanel("转换移动端资源包", m_pProjectPath, ""); 36 | if (null != pPath && 0 < pPath.Length) 37 | { 38 | string[] aFile = Directory.GetFiles(pPath, "*.assetbundle", SearchOption.AllDirectories); 39 | 40 | foreach (string pFile in aFile) 41 | { 42 | AssetBundle pAsset = AssetBundle.LoadFromFile(pFile); 43 | UnityEngine.Object pPrefab = pAsset.LoadAsset(pAsset.GetAllAssetNames()[0]); 44 | 45 | m_pPacker.PackObject(pPrefab as GameObject, pFile + ".bin"); 46 | 47 | pAsset.Unload(false); 48 | 49 | Debug.LogError("转换文件:" + pFile); 50 | } 51 | } 52 | else 53 | { 54 | Debug.LogWarning("请选择一个文件夹!"); 55 | } 56 | } 57 | 58 | [MenuItem("GameObject/导出移动端模型", false, 0)] 59 | static void ExportWX() 60 | { 61 | if (null != Selection.activeGameObject) 62 | { 63 | m_pPacker.PackObject(Selection.activeGameObject); 64 | 65 | Debug.LogWarning("导出移动端模型完成:" + Selection.activeGameObject.name); 66 | } 67 | else 68 | { 69 | Debug.LogWarning("请选中一个对象!"); 70 | } 71 | } 72 | 73 | [MenuItem("Assets/加载并优化模型", false, 0)] 74 | static void LoadOptimize() 75 | { 76 | string pFile = EditorUtility.OpenFilePanel("加载模型", m_pProjectPath, "assetbundle"); 77 | if (null != pFile && 0 < pFile.Length) 78 | { 79 | AssetBundle pAsset = AssetBundle.LoadFromFile(pFile); 80 | UnityEngine.Object pPrefab = pAsset.LoadAsset(pAsset.GetAllAssetNames()[0]); 81 | 82 | GameObject pObject = m_pOptimizer.Combine(pPrefab as GameObject); 83 | pObject.name = pPrefab.name; 84 | 85 | pAsset.Unload(true); 86 | 87 | Debug.LogWarning("加载优化模型完成:" + pFile); 88 | } 89 | else 90 | { 91 | Debug.LogWarning("请选择一个文件!"); 92 | } 93 | } 94 | 95 | [MenuItem("Assets/优化模型", false, 0)] 96 | static void Optimize() 97 | { 98 | if (null != Selection.activeGameObject) 99 | { 100 | GameObject pObject = m_pOptimizer.Combine(Selection.activeGameObject); 101 | pObject.name = Selection.activeGameObject.name; 102 | 103 | Debug.LogWarning("优化模型完成:" + pObject.name); 104 | } 105 | else 106 | { 107 | Debug.LogWarning("请选中一个对象!"); 108 | } 109 | } 110 | 111 | [MenuItem("Assets/导出模型/WebGL", false, 0)] 112 | static void ExportWebGL() 113 | { 114 | Export("webgl"); 115 | } 116 | 117 | [MenuItem("Assets/导出模型/PC", false, 0)] 118 | static void ExportPC() 119 | { 120 | Export("pc"); 121 | } 122 | 123 | 124 | static void Export(string pTarget) 125 | { 126 | if (null != Selection.activeGameObject) 127 | { 128 | string pObjectName = Selection.activeGameObject.name; 129 | string pPrefabName = AssetDatabase.GetAssetPath(Selection.activeObject); 130 | 131 | string pName = "opt-" + pTarget + "-" + pObjectName; 132 | string pFile = EditorUtility.SaveFilePanel("保存模型", m_pProjectPath, pName, "assetbundle"); 133 | string pPath = pFile.Substring(0, pFile.LastIndexOf('/')); 134 | 135 | BuildTarget eTarget = "webgl" == pTarget ? BuildTarget.WebGL : BuildTarget.StandaloneWindows; 136 | 137 | AssetBundleBuild[] aBuild = new AssetBundleBuild[1]; 138 | aBuild[0].assetBundleName = pName; 139 | aBuild[0].assetNames = new string[] { pPrefabName }; 140 | aBuild[0].assetBundleVariant = "assetbundle"; 141 | 142 | if (File.Exists(pFile)) 143 | { 144 | File.Delete(pFile); 145 | } 146 | 147 | BuildPipeline.BuildAssetBundles(pPath, aBuild, ( 148 | BuildAssetBundleOptions.ForceRebuildAssetBundle | 149 | BuildAssetBundleOptions.StrictMode 150 | ), eTarget); 151 | 152 | AssetDatabase.Refresh(); 153 | 154 | Debug.LogWarning("导出模型完成:" + pFile); 155 | 156 | System.Diagnostics.Process.Start("explorer.exe", pPath.Replace('/', '\\')); 157 | } 158 | else 159 | { 160 | Debug.LogWarning("请选中一个对象!"); 161 | } 162 | } 163 | 164 | 165 | private static string m_pPath = Application.dataPath + "/"; 166 | private static string m_pProjectPath = m_pPath.Substring(0, m_pPath.Length - 7); 167 | private static Optimizer m_pOptimizer = new Optimizer(); 168 | private static Packer m_pPacker = new Packer(); 169 | } 170 | 171 | 172 | public class Optimizer 173 | { 174 | /// 175 | /// 合并优化对象。 176 | /// 177 | /// 待优化对象。 178 | /// 已优化对象。 179 | public GameObject Combine(GameObject pObject) 180 | { 181 | List pIndependentList = new List(); 182 | GameObject pNewObject = null; 183 | 184 | Independent(pObject.transform, pIndependentList); 185 | 186 | foreach (Group pItem in pIndependentList) 187 | { 188 | Collect(pItem.m_pTransform, pItem, pIndependentList); 189 | Create(pItem); 190 | 191 | Debug.LogError(pItem.m_pTransform.name + " " + pItem.m_pFilterList.Count); 192 | } 193 | 194 | foreach (Group pItem in pIndependentList) 195 | { 196 | if (null != pItem.m_pTransform.parent) 197 | { 198 | foreach (Group pParent in pIndependentList) 199 | { 200 | if (pParent.m_pTransform == pItem.m_pTransform.parent) 201 | { 202 | pItem.m_pObject.transform.parent = pParent.m_pObject.transform; 203 | } 204 | } 205 | } 206 | else 207 | { 208 | pNewObject = pItem.m_pObject; 209 | } 210 | } 211 | 212 | CreatePrefab(pNewObject); 213 | 214 | return pNewObject; 215 | } 216 | 217 | /// 218 | /// 创建分组合并网格后的新对象。 219 | /// 220 | /// 分组。 221 | private void Create(Group pGroup) 222 | { 223 | MeshFilter[] aFilter = pGroup.m_pFilterList.ToArray(); 224 | Matrix4x4 mMatrix = Matrix4x4.identity; /*pItem.m_pTransform.worldToLocalMatrix;*/ 225 | 226 | Dictionary pSubDict = new Dictionary(); 227 | int nVertexCount = 0; 228 | 229 | for (int i = 0; i < aFilter.Length; i++) 230 | { 231 | MeshFilter pFilter = aFilter[i]; 232 | MeshRenderer pRenderer = pFilter.GetComponent(); 233 | Mesh pMesh = pFilter.sharedMesh; 234 | Matrix4x4 mTrans = mMatrix * pFilter.transform.localToWorldMatrix; 235 | 236 | nVertexCount += pMesh.vertexCount; 237 | 238 | for (int j = 0; j < pMesh.subMeshCount; j++) 239 | { 240 | CombineInstance mInstance = new CombineInstance(); 241 | mInstance.mesh = pMesh; 242 | mInstance.transform = mTrans; 243 | mInstance.subMeshIndex = j; 244 | 245 | Material pMaterial = pRenderer.sharedMaterials[j]; 246 | MaterialGroup pSub = null; 247 | 248 | if (pSubDict.ContainsKey(pMaterial)) 249 | { 250 | pSub = pSubDict[pMaterial]; 251 | } 252 | else 253 | { 254 | pSub = new MaterialGroup(); 255 | pSub.m_pMaterial = pMaterial; 256 | pSubDict.Add(pMaterial, pSub); 257 | } 258 | 259 | pSub.m_aInstance.Add(mInstance); 260 | } 261 | } 262 | 263 | foreach (MaterialGroup pSub in pSubDict.Values) 264 | { 265 | if (1 == pSub.m_aInstance.Count) 266 | { 267 | pSub.m_pInstance = pSub.m_aInstance[0]; 268 | } 269 | else 270 | { 271 | Mesh pSubMesh = new Mesh(); 272 | 273 | pSubMesh.indexFormat = 65535 < nVertexCount ? UnityEngine.Rendering.IndexFormat.UInt32 : UnityEngine.Rendering.IndexFormat.UInt16; 274 | pSubMesh.CombineMeshes(pSub.m_aInstance.ToArray(), true, true, false); 275 | 276 | pSub.m_pInstance.mesh = pSubMesh; 277 | pSub.m_pInstance.transform = Matrix4x4.identity; 278 | pSub.m_pInstance.subMeshIndex = 0; 279 | } 280 | } 281 | 282 | int nSubCount = pSubDict.Values.Count; 283 | CombineInstance[] aInstance = new CombineInstance[nSubCount]; 284 | Material[] aMaterial = new Material[nSubCount]; 285 | 286 | foreach (MaterialGroup pSub in pSubDict.Values) 287 | { 288 | nSubCount--; 289 | aInstance[nSubCount] = pSub.m_pInstance; 290 | aMaterial[nSubCount] = pSub.m_pMaterial; 291 | } 292 | 293 | GameObject pNewObject = new GameObject(pGroup.m_pTransform.gameObject.name); 294 | MeshFilter pNewFilter = pNewObject.AddComponent(); 295 | MeshRenderer pNewRenderer = pNewObject.AddComponent(); 296 | Mesh pNewMesh = new Mesh(); 297 | 298 | pNewMesh.indexFormat = 65535 < nVertexCount ? UnityEngine.Rendering.IndexFormat.UInt32 : UnityEngine.Rendering.IndexFormat.UInt16; 299 | pNewMesh.CombineMeshes(aInstance, false, true, false); 300 | pNewMesh.name = pNewObject.name; 301 | 302 | pNewFilter.mesh = pNewMesh; 303 | pNewRenderer.sharedMaterials = aMaterial; 304 | 305 | pGroup.m_pObject = pNewObject; 306 | } 307 | 308 | /// 309 | /// 创建预制件资源。 310 | /// 311 | /// 对象。 312 | /// 是否新建资源,AB资源需要新建。 313 | private void CreatePrefab(GameObject pObject) 314 | { 315 | if (null == pObject) 316 | { 317 | return; 318 | } 319 | 320 | string pPathRoot = "Assets/Optimize/" + pObject.name; 321 | string pPathTexture = pPathRoot + "/Texture"; 322 | string pPathMaterial = pPathRoot + "/Material"; 323 | string pPathMesh = pPathRoot + "/Mesh"; 324 | 325 | if (!AssetDatabase.IsValidFolder("Assets/Optimize")) 326 | { 327 | AssetDatabase.CreateFolder("Assets", "Optimize"); 328 | } 329 | 330 | if (!AssetDatabase.IsValidFolder(pPathRoot)) 331 | { 332 | AssetDatabase.CreateFolder("Assets/Optimize", pObject.name); 333 | } 334 | 335 | if (!AssetDatabase.IsValidFolder(pPathTexture)) 336 | { 337 | AssetDatabase.CreateFolder(pPathRoot, "Texture"); 338 | } 339 | 340 | if (!AssetDatabase.IsValidFolder(pPathMaterial)) 341 | { 342 | AssetDatabase.CreateFolder(pPathRoot, "Material"); 343 | } 344 | 345 | if (!AssetDatabase.IsValidFolder(pPathMesh)) 346 | { 347 | AssetDatabase.CreateFolder(pPathRoot, "Mesh"); 348 | } 349 | 350 | 351 | MeshFilter[] aFilter = pObject.GetComponentsInChildren(); 352 | 353 | for (int i = 0; i < aFilter.Length; i++) 354 | { 355 | Mesh pMesh = aFilter[i].sharedMesh; 356 | if (null != pMesh) 357 | { 358 | pMesh.Optimize(); 359 | pMesh.name = "" + i + "-" + pMesh.name; 360 | 361 | AssetDatabase.CreateAsset(pMesh, pPathMesh + "/" + pMesh.name + ".asset"); 362 | } 363 | } 364 | 365 | 366 | MeshRenderer[] aRenderer = pObject.GetComponentsInChildren(); 367 | Dictionary pTextureList = new Dictionary(); 368 | List pMaterialList = new List(); 369 | 370 | for (int i = 0; i < aRenderer.Length; i++) 371 | { 372 | Material[] aMaterial = aRenderer[i].sharedMaterials; 373 | 374 | for (int j = 0; j < aMaterial.Length; j++) 375 | { 376 | Material pMaterial = aMaterial[j]; 377 | 378 | if (!pMaterialList.Contains(pMaterial)) 379 | { 380 | if (AssetDatabase.Contains(pMaterial)) 381 | { 382 | AssetDatabase.RemoveObjectFromAsset(pMaterial); 383 | } 384 | 385 | pMaterialList.Add(pMaterial); 386 | } 387 | else 388 | { 389 | continue; 390 | } 391 | 392 | Shader pShader = Shader.Find(pMaterial.shader.name); 393 | pMaterial.shader = pShader; 394 | 395 | int nCount = ShaderUtil.GetPropertyCount(pShader); 396 | for (int k = 0; k < nCount; k++) 397 | { 398 | switch (ShaderUtil.GetPropertyType(pShader, k)) 399 | { 400 | case ShaderUtil.ShaderPropertyType.TexEnv: 401 | string pName = ShaderUtil.GetPropertyName(pShader, k); 402 | Texture pTexture = pMaterial.GetTexture(pName); 403 | if (pTexture) 404 | { 405 | if (!pTextureList.ContainsKey(pTexture)) 406 | { 407 | if (pTexture.dimension == UnityEngine.Rendering.TextureDimension.Tex2D) 408 | { 409 | Texture2D pNewTexture = OptimizeTrxture((Texture2D)pTexture, true, pPathTexture, pTextureList.Count); 410 | pTextureList.Add(pTexture, pNewTexture); 411 | 412 | pMaterial.SetTexture(pName, pNewTexture); 413 | } 414 | else 415 | { 416 | pTextureList.Add(pTexture, pTexture); 417 | } 418 | } 419 | else 420 | { 421 | pMaterial.SetTexture(pName, pTextureList[pTexture]); 422 | } 423 | } 424 | break; 425 | default: 426 | break; 427 | } 428 | } 429 | } 430 | 431 | aRenderer[i].receiveShadows = false; 432 | aRenderer[i].shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; 433 | aRenderer[i].reflectionProbeUsage = UnityEngine.Rendering.ReflectionProbeUsage.Off; 434 | aRenderer[i].lightProbeUsage = UnityEngine.Rendering.LightProbeUsage.Off; 435 | } 436 | 437 | for (int i = 0; i < pMaterialList.Count; i++) 438 | { 439 | pMaterialList[i].name = "" + i + "-" + pMaterialList[i].name; 440 | 441 | AssetDatabase.CreateAsset(pMaterialList[i], pPathMaterial + "/" + pMaterialList[i].name + ".mat"); 442 | } 443 | 444 | 445 | AssetDatabase.Refresh(); 446 | PrefabUtility.SaveAsPrefabAsset(pObject, pPathRoot + "/" + pObject.name + ".prefab"); 447 | } 448 | 449 | /// 450 | /// 优化转换贴图。 451 | /// 452 | /// 原始贴图。 453 | /// 返回优化后贴图。 454 | private Texture2D OptimizeTrxture(Texture2D pOrgin, bool bOpacity, string pPath, int nIndex) 455 | { 456 | Texture2D pUncompress = null; 457 | Texture2D pSwitch = new Texture2D(pOrgin.width, pOrgin.height, pOrgin.format, pOrgin.mipmapCount > 1, false); 458 | pSwitch.LoadRawTextureData(pOrgin.GetRawTextureData()); 459 | pSwitch.Apply(false, false); 460 | 461 | if (bOpacity) 462 | { 463 | pUncompress = new Texture2D(pOrgin.width / 2, pOrgin.height / 2, TextureFormat.RGB24, true, false); 464 | } 465 | else 466 | { 467 | pUncompress = new Texture2D(pOrgin.width, pOrgin.height, TextureFormat.RGBA32, true, false); 468 | } 469 | 470 | for (int level = 0; level < pSwitch.mipmapCount - 1; level++) 471 | { 472 | pUncompress.SetPixels(pSwitch.GetPixels(level + 1), level); 473 | } 474 | 475 | pUncompress.Apply(false, false); 476 | 477 | 478 | string pName = "" + (nIndex) + "-" + pOrgin.name; 479 | string pImageFile = pPath + "/" + pName + ".jpg"; 480 | byte[] aImageData = pUncompress.EncodeToJPG(); 481 | 482 | File.WriteAllBytes(pImageFile, aImageData); 483 | AssetDatabase.ImportAsset(pImageFile); 484 | TextureImporter pImporter = AssetImporter.GetAtPath(pImageFile) as TextureImporter; 485 | 486 | if (null != pImporter) 487 | { 488 | pImporter.compressionQuality = 50; 489 | pImporter.crunchedCompression = true; 490 | pImporter.isReadable = false; 491 | pImporter.SaveAndReimport(); 492 | } 493 | 494 | AssetDatabase.Refresh(); 495 | 496 | Texture.DestroyImmediate(pSwitch); 497 | Texture.DestroyImmediate(pUncompress); 498 | 499 | Texture2D pTexture = AssetDatabase.LoadAssetAtPath(pImageFile); 500 | 501 | return pTexture; 502 | } 503 | 504 | /// 505 | /// 收集一个分组所有的网格组件。 506 | /// 507 | /// 分组主对象。 508 | /// 分组。 509 | /// 分组列表 510 | private void Collect(Transform pObject, Group pGroup, List pIndependentList) 511 | { 512 | MeshFilter pFilter = pObject.GetComponent(); 513 | if (null != pFilter) 514 | { 515 | MeshRenderer pRenderer = pFilter.GetComponent(); 516 | 517 | if (!(null == pFilter.sharedMesh || null == pRenderer || !pRenderer.enabled || pRenderer.gameObject.name.Contains("ThinTree"))) 518 | { 519 | pGroup.m_pFilterList.Add(pFilter); 520 | } 521 | } 522 | 523 | foreach (Transform pChild in pObject) 524 | { 525 | bool bCombine = true; 526 | 527 | foreach (Group pGroup_ in pIndependentList) 528 | { 529 | if (pGroup_.m_pTransform == pChild) 530 | { 531 | bCombine = false; 532 | break; 533 | } 534 | } 535 | 536 | if (bCombine) 537 | { 538 | Collect(pChild, pGroup, pIndependentList); 539 | } 540 | } 541 | } 542 | 543 | /// 544 | /// 确认对象是否独立。 545 | /// 546 | /// 对象。 547 | /// 独立对象存储列表。 548 | /// 独立返回对象变换组件。 549 | private Transform Independent(Transform pObject, List pList) 550 | { 551 | // 独立子节点列表 552 | List pIndependentList = new List(); 553 | 554 | // 遍历所有子节点,确认它们是否需要独立存在 555 | foreach (Transform pChild in pObject) 556 | { 557 | Transform pIndependent = Independent(pChild, pList); 558 | if (null != pIndependent) 559 | { 560 | pIndependentList.Add(pIndependent); 561 | } 562 | } 563 | 564 | // 如果节点存在独立子节点,或者节点被标记为独立,又或者节点为跟节点,此时该节点独立 565 | if (0 < pIndependentList.Count || 0 < CheckLayer(pObject.gameObject.layer) || null == pObject.parent) 566 | { 567 | Group pGroup = new Group(); 568 | pGroup.m_pTransform = pObject; 569 | 570 | pList.Add(pGroup); 571 | 572 | return pObject; 573 | } 574 | 575 | return null; 576 | } 577 | 578 | /// 579 | /// 确认对象被标记了特殊层。 580 | /// 581 | /// 对象层标识。 582 | /// 返回独立标记。 583 | private int CheckLayer(int nLayer) 584 | { 585 | switch (nLayer) 586 | { 587 | case 11/*AEdge*/: 588 | return 1; 589 | case 12/*AAreaBottom*/: 590 | return 1; 591 | case 13/*AAreaTop*/: 592 | return 1; 593 | case 14/*AHoleModel*/: 594 | return 1; 595 | case 15/*AEdgeModel*/: 596 | return 1; 597 | case 16/*EBuildingModel*/: 598 | return 1; 599 | case 17/*EStoreyModel*/: 600 | return 1; 601 | case 18/*EFurnitureModel*/: 602 | return 1; 603 | case 19/*EAssetsModel*/: 604 | return 1; 605 | case 20/*EPanel*/: 606 | return 1; 607 | case 21/*EGroup*/: 608 | return 0; 609 | case 22/*EPlaceholder*/: 610 | return 0; 611 | default: 612 | break; 613 | } 614 | 615 | return 0; 616 | } 617 | 618 | 619 | #region 嵌套类型 620 | public class Group 621 | { 622 | public GameObject m_pObject = null; 623 | public Transform m_pTransform = null; 624 | public List m_pFilterList = new List(); 625 | } 626 | 627 | public class MaterialGroup 628 | { 629 | public List m_aInstance = new List(); 630 | public Material m_pMaterial = null; 631 | public CombineInstance m_pInstance; 632 | } 633 | #endregion 634 | } 635 | 636 | 637 | public class Packer 638 | { 639 | /// 640 | /// 构造函数。 641 | /// 642 | public Packer() 643 | { 644 | } 645 | 646 | /// 647 | /// 打包对象。 648 | /// 649 | /// 650 | public void PackObject(GameObject pObject, string pFile ="xxx.bin") 651 | { 652 | // 版本,头数据大小,名称数据大小 653 | Group_.g_nTotalHeader = 4 + 4 + 4; 654 | Group_.g_nTotalName = 0; 655 | 656 | m_aCroup = new Group_[5]; 657 | 658 | for (int i = 0; i < m_aCroup.Length; i++) 659 | { 660 | m_aCroup[i] = new Group_(); 661 | } 662 | 663 | 664 | Pack(pObject, -1); 665 | 666 | 667 | FileStream pStream = new FileStream(pFile, FileMode.OpenOrCreate); 668 | BinaryWriter pWriter = new BinaryWriter(pStream); 669 | 670 | pWriter.Write(1); 671 | pWriter.Write(Group_.g_nTotalHeader - 12); 672 | pWriter.Write(Group_.g_nTotalName); 673 | 674 | int nNameOffset = Group_.g_nTotalHeader; 675 | int nDataOffset = Group_.g_nTotalHeader + Group_.g_nTotalName; 676 | 677 | for (int i = 0; i < m_aCroup.Length; i++) 678 | { 679 | m_aCroup[i].WriteHeader(pWriter, ref nNameOffset, ref nDataOffset); 680 | } 681 | 682 | for (int i = 0; i < m_aCroup.Length; i++) 683 | { 684 | m_aCroup[i].WriteNameBuffer(pWriter); 685 | } 686 | 687 | for (int i = 0; i < m_aCroup.Length; i++) 688 | { 689 | m_aCroup[i].WriteDataBuffer(pWriter); 690 | } 691 | 692 | for (int i = 0; i < m_aCroup.Length; i++) 693 | { 694 | m_aCroup[i].Close(); 695 | } 696 | 697 | pWriter.Close(); 698 | pStream.Close(); 699 | } 700 | 701 | /// 702 | /// 收集数据。 703 | /// 704 | /// 705 | private void Pack(GameObject pObject, int nParent) 706 | { 707 | // [是否启用,父级索引,网格索引,网格渲染器索引,本地变换数据] 708 | 709 | int nMesh = -1; 710 | int nMeshRenderer = -1; 711 | int nObject = -1; 712 | 713 | MeshFilter pFilter = pObject.GetComponent(); 714 | if (null != pFilter) 715 | { 716 | MeshRenderer pRenderer = pFilter.GetComponent(); 717 | if (null != pFilter.sharedMesh && null != pRenderer) 718 | { 719 | nMesh = m_aCroup[MESH].FindObject(pFilter.sharedMesh); 720 | if (-1 == nMesh) 721 | { 722 | if (pFilter.sharedMesh.isReadable) 723 | { 724 | nMesh = m_aCroup[MESH].AddObject(pFilter.sharedMesh); 725 | Pack(pFilter.sharedMesh); 726 | } 727 | else 728 | { 729 | Debug.LogError("PackMesh(网格数据不可读): " + pFilter.sharedMesh.name); 730 | } 731 | } 732 | 733 | foreach (Material pMaterial in pRenderer.sharedMaterials) 734 | { 735 | int nMaterial = m_aCroup[MATERIAL].FindObject(pMaterial); 736 | if (-1 == nMaterial) 737 | { 738 | nMaterial = m_aCroup[MATERIAL].AddObject(pMaterial); 739 | Pack(pMaterial); 740 | } 741 | } 742 | 743 | if (-1 == nMeshRenderer) 744 | { 745 | nMeshRenderer = m_aCroup[RENDERER].AddObject(pRenderer); 746 | Pack(pRenderer); 747 | } 748 | } 749 | } 750 | 751 | if (-1 == nObject) 752 | { 753 | nObject = m_aCroup[OBJECT].AddObject(pObject); 754 | 755 | m_aCroup[OBJECT].WriteName(pObject.name); 756 | 757 | if (-1 == nParent) 758 | { 759 | m_aCroup[OBJECT].WriteData(1); 760 | } 761 | else 762 | { 763 | m_aCroup[OBJECT].WriteData(pObject.activeInHierarchy ? 1 : 0); 764 | } 765 | 766 | m_aCroup[OBJECT].WriteData(nMesh); 767 | m_aCroup[OBJECT].WriteData(nMeshRenderer); 768 | 769 | m_aCroup[OBJECT].WriteData(nParent); 770 | 771 | m_aCroup[OBJECT].WriteData(pObject.transform.localPosition); 772 | m_aCroup[OBJECT].WriteData(pObject.transform.localRotation); 773 | m_aCroup[OBJECT].WriteData(pObject.transform.localScale); 774 | 775 | Debug.LogError("OBJECT: " + nParent); 776 | } 777 | 778 | 779 | foreach (Transform pChild in pObject.transform) 780 | { 781 | Pack(pChild.gameObject, nObject); 782 | } 783 | } 784 | 785 | /// 786 | /// 打包网格对象。 787 | /// 788 | /// 789 | private void Pack(Mesh pMesh) 790 | { 791 | //[顶点数量,输入数量,子网格数量,{ 输入插槽,数据地址 },{ 图元类型,数据数量,数据地址 }] 792 | 793 | m_aCroup[MESH].WriteName(pMesh.name); 794 | 795 | Vector3[] aPosition = pMesh.vertices; 796 | Vector3[] aNormal = pMesh.normals; 797 | Vector2[] aUV = pMesh.uv; 798 | 799 | int nInputCount = 1 + (null == aNormal ? 0 : 1) + (null == aUV ? 0 : 1); 800 | int nSubCount = pMesh.subMeshCount; 801 | int nDescCount = 3 + 2 * nInputCount + 3 * nSubCount; 802 | int[] aDesc = new int[nDescCount]; 803 | 804 | int nIndex = 0; 805 | int nAddr = 4 * nDescCount; 806 | 807 | aDesc[nIndex++] = aPosition.Length; 808 | aDesc[nIndex++] = nInputCount; 809 | aDesc[nIndex++] = nSubCount; 810 | 811 | if (null != aPosition) 812 | { 813 | aDesc[nIndex++] = 0; 814 | aDesc[nIndex++] = nAddr; 815 | 816 | nAddr += 12 * aPosition.Length; 817 | } 818 | 819 | if (null != aNormal) 820 | { 821 | aDesc[nIndex++] = 1; 822 | aDesc[nIndex++] = nAddr; 823 | 824 | nAddr += 12 * aPosition.Length; 825 | } 826 | 827 | if (null != aUV) 828 | { 829 | aDesc[nIndex++] = 2; 830 | aDesc[nIndex++] = nAddr; 831 | 832 | nAddr += 8 * aPosition.Length; 833 | } 834 | 835 | for (int i = 0; i < nSubCount; i++) 836 | { 837 | int[] aIndex = pMesh.GetTriangles(i); 838 | 839 | aDesc[nIndex++] = 0; 840 | aDesc[nIndex++] = aIndex.Length; 841 | aDesc[nIndex++] = nAddr; 842 | 843 | nAddr += 4 * aIndex.Length; 844 | } 845 | 846 | m_aCroup[MESH].WriteData(aDesc); 847 | m_aCroup[MESH].WriteData(aPosition); 848 | m_aCroup[MESH].WriteData(aNormal); 849 | m_aCroup[MESH].WriteData(aUV); 850 | 851 | for (int i = 0; i < nSubCount; i++) 852 | { 853 | m_aCroup[MESH].WriteData(pMesh.GetTriangles(i)); 854 | } 855 | 856 | Debug.LogError("MESH: " + pMesh.vertexCount); 857 | } 858 | 859 | /// 860 | /// 打包材质对象。 861 | /// 862 | /// 863 | private void Pack(Material pMaterial) 864 | { 865 | // [着色器名称,渲染模式,主颜色,贴图数量,贴图名称,贴图索引,贴图变换...] 866 | 867 | m_aCroup[MATERIAL].WriteName(pMaterial.name); 868 | 869 | int nMode = 0; 870 | if (pMaterial.HasProperty("_Mode")) 871 | { 872 | float nMode_ = pMaterial.GetFloat("_Mode"); 873 | if (2.0f == nMode_) 874 | { 875 | nMode = 2; 876 | } 877 | 878 | if (3.0f == nMode) 879 | { 880 | nMode = 1; 881 | } 882 | } 883 | 884 | m_aCroup[MATERIAL].WriteData(pMaterial.shader.name); 885 | m_aCroup[MATERIAL].WriteData(nMode); 886 | 887 | m_aCroup[MATERIAL].WriteData(pMaterial.color); 888 | 889 | Dictionary pImageList = new Dictionary(); 890 | 891 | int nCount = ShaderUtil.GetPropertyCount(pMaterial.shader); 892 | for (int k = 0; k < nCount; k++) 893 | { 894 | switch (ShaderUtil.GetPropertyType(pMaterial.shader, k)) 895 | { 896 | case ShaderUtil.ShaderPropertyType.TexEnv: 897 | string pName = ShaderUtil.GetPropertyName(pMaterial.shader, k); 898 | Texture pTexture = pMaterial.GetTexture(pName); 899 | if (pTexture && pTexture.dimension == UnityEngine.Rendering.TextureDimension.Tex2D) 900 | { 901 | int nImage = m_aCroup[IMAGE].FindObject(pTexture); 902 | if (-1 == nImage) 903 | { 904 | nImage = m_aCroup[IMAGE].AddObject(pTexture); 905 | Pack((Texture2D)pTexture); 906 | } 907 | 908 | if (-1 != nImage) 909 | { 910 | pImageList.Add(pName, nImage); 911 | } 912 | } 913 | break; 914 | default: 915 | break; 916 | } 917 | } 918 | 919 | m_aCroup[MATERIAL].WriteData(pImageList.Count); 920 | 921 | foreach (var pImage in pImageList) 922 | { 923 | m_aCroup[MATERIAL].WriteData(pImage.Key); 924 | m_aCroup[MATERIAL].WriteData(pImage.Value); 925 | 926 | Vector2 mOffset = pMaterial.GetTextureOffset(pImage.Key); 927 | Vector2 mScale = pMaterial.GetTextureScale(pImage.Key); 928 | 929 | m_aCroup[MATERIAL].WriteData(mOffset); 930 | m_aCroup[MATERIAL].WriteData(mScale); 931 | } 932 | 933 | Debug.LogError("MATERIAL: " + pMaterial.shader.name); 934 | } 935 | 936 | /// 937 | /// 打包贴图对象。 938 | /// 939 | /// 940 | private void Pack(Texture2D pOrgin) 941 | { 942 | // [数据大小,数据] 943 | 944 | Texture2D pUncompress = null; 945 | Texture2D pSwitch = new Texture2D(pOrgin.width, pOrgin.height, pOrgin.format, pOrgin.mipmapCount > 1, false); 946 | pSwitch.LoadRawTextureData(pOrgin.GetRawTextureData()); 947 | pSwitch.Apply(false, false); 948 | 949 | if (!pOrgin.alphaIsTransparency) 950 | { 951 | pUncompress = new Texture2D(pOrgin.width / 2, pOrgin.height / 2, TextureFormat.RGB24, true, false); 952 | } 953 | else 954 | { 955 | pUncompress = new Texture2D(pOrgin.width, pOrgin.height, TextureFormat.RGBA32, true, false); 956 | } 957 | 958 | for (int level = 0; level < pSwitch.mipmapCount - 1; level++) 959 | { 960 | pUncompress.SetPixels(pSwitch.GetPixels(level + 1), level); 961 | } 962 | 963 | pUncompress.Apply(false, false); 964 | 965 | byte[] aData = pOrgin.alphaIsTransparency ? pUncompress.EncodeToPNG() : pUncompress.EncodeToJPG(); 966 | 967 | Texture2D.DestroyImmediate(pUncompress); 968 | Texture2D.DestroyImmediate(pSwitch); 969 | 970 | m_aCroup[IMAGE].WriteName(pOrgin.name); 971 | m_aCroup[IMAGE].WriteData(aData.Length); 972 | m_aCroup[IMAGE].WriteData(aData); 973 | 974 | Debug.LogError("IMAGE: " + aData.Length); 975 | } 976 | 977 | /// 978 | /// 打包网格对象。 979 | /// 980 | /// 981 | private void Pack(MeshRenderer pRenderer) 982 | { 983 | // [是否启用,材质数量,材质列表] 984 | 985 | m_aCroup[RENDERER].WriteName(null); 986 | 987 | m_aCroup[RENDERER].WriteData(pRenderer.enabled ? 1 : 0); 988 | m_aCroup[RENDERER].WriteData(pRenderer.sharedMaterials.Length); 989 | 990 | foreach (Material pMaterial in pRenderer.sharedMaterials) 991 | { 992 | int nIndex = m_aCroup[MATERIAL].FindObject(pMaterial); 993 | m_aCroup[RENDERER].WriteData(nIndex); 994 | } 995 | 996 | Debug.LogError("RENDERER: " + pRenderer.sharedMaterials.Length); 997 | } 998 | 999 | 1000 | /// 1001 | /// 各类数据组[0-图片,1-材质,2-网格,3-网格渲染器,4-对象]。 1002 | /// 1003 | private Group_[] m_aCroup; 1004 | private const int IMAGE = 0; 1005 | private const int MATERIAL = 1; 1006 | private const int MESH = 2; 1007 | private const int RENDERER = 3; 1008 | private const int OBJECT = 4; 1009 | 1010 | #region 嵌套类型 1011 | /// 1012 | /// 数据组。 1013 | /// 1014 | private class Group_ 1015 | { 1016 | /// 1017 | /// 构造函数。 1018 | /// 1019 | public Group_() 1020 | { 1021 | m_aDesc = new List(); 1022 | 1023 | m_pNameStream = new MemoryStream(); 1024 | m_pNameWriter = new BinaryWriter(m_pNameStream); 1025 | 1026 | m_pDataStream = new MemoryStream(); 1027 | m_pDataWriter = new BinaryWriter(m_pDataStream); 1028 | 1029 | m_pDict = new Dictionary(); 1030 | 1031 | // 数量、名称地址、数据地址 1032 | g_nTotalHeader += 4 + 4 + 4; 1033 | } 1034 | 1035 | /// 1036 | /// 关闭数据组。 1037 | /// 1038 | public void Close() 1039 | { 1040 | m_pNameWriter.Close(); 1041 | m_pNameStream.Close(); 1042 | 1043 | m_pDataWriter.Close(); 1044 | m_pDataStream.Close(); 1045 | } 1046 | 1047 | /// 1048 | /// 写入数据组头数据。 1049 | /// 1050 | /// 1051 | /// 1052 | /// 1053 | public void WriteHeader(BinaryWriter pWriter, ref int nNameOffset, ref int nDataOffset) 1054 | { 1055 | pWriter.Write(m_aDesc.Count / 2); 1056 | pWriter.Write(nNameOffset); 1057 | pWriter.Write(nDataOffset); 1058 | 1059 | foreach (int i in m_aDesc) 1060 | { 1061 | pWriter.Write(i); 1062 | } 1063 | 1064 | nNameOffset += (int)m_pNameStream.Position; 1065 | nDataOffset += (int)m_pDataStream.Position; 1066 | } 1067 | 1068 | /// 1069 | /// 写入名称缓存。 1070 | /// 1071 | /// 1072 | public void WriteNameBuffer(BinaryWriter pWriter) 1073 | { 1074 | pWriter.Write(m_pNameStream.GetBuffer(), 0, (int)m_pNameStream.Position); 1075 | } 1076 | 1077 | /// 1078 | /// 写入名称缓存。 1079 | /// 1080 | /// 1081 | public void WriteDataBuffer(BinaryWriter pWriter) 1082 | { 1083 | pWriter.Write(m_pDataStream.GetBuffer(), 0, (int)m_pDataStream.Position); 1084 | } 1085 | 1086 | 1087 | /// 1088 | /// 写入名称。 1089 | /// 1090 | /// 1091 | public void WriteName(string pName) 1092 | { 1093 | if (null == pName) 1094 | { 1095 | pName = "UNNAME"; 1096 | } 1097 | 1098 | byte[] aName = System.Text.ASCIIEncoding.UTF8.GetBytes(pName); 1099 | 1100 | m_pNameWriter.Write(aName.Length); 1101 | 1102 | AddName((int)m_pNameStream.Position); 1103 | AddData((int)m_pDataStream.Position); 1104 | 1105 | m_pNameWriter.Write(aName); 1106 | m_pNameWriter.Write((byte)0); 1107 | 1108 | // 名称地址偏移、数据地址偏移 1109 | g_nTotalHeader += 4 + 4; 1110 | g_nTotalName += 4 + aName.Length + 1; 1111 | } 1112 | 1113 | /// 1114 | /// 写入数据。 1115 | /// 1116 | /// 1117 | public void WriteData(byte[] aData) 1118 | { 1119 | if (null == aData) 1120 | { 1121 | return; 1122 | } 1123 | 1124 | m_pDataWriter.Write(aData); 1125 | } 1126 | 1127 | /// 1128 | /// 写入数据。 1129 | /// 1130 | /// 1131 | public void WriteData(int[] aData) 1132 | { 1133 | if (null == aData) 1134 | { 1135 | return; 1136 | } 1137 | 1138 | for (int i = 0; i < aData.Length; i++) 1139 | { 1140 | m_pDataWriter.Write(aData[i]); 1141 | } 1142 | } 1143 | 1144 | /// 1145 | /// 写入数据。 1146 | /// 1147 | /// 1148 | public void WriteData(Vector3[] aData) 1149 | { 1150 | if (null == aData) 1151 | { 1152 | return; 1153 | } 1154 | 1155 | for (int i = 0; i < aData.Length; i++) 1156 | { 1157 | m_pDataWriter.Write(aData[i].x); 1158 | m_pDataWriter.Write(aData[i].y); 1159 | m_pDataWriter.Write(aData[i].z); 1160 | } 1161 | } 1162 | 1163 | /// 1164 | /// 写入数据。 1165 | /// 1166 | /// 1167 | public void WriteData(Vector2[] aData) 1168 | { 1169 | if (null == aData) 1170 | { 1171 | return; 1172 | } 1173 | 1174 | for (int i = 0; i < aData.Length; i++) 1175 | { 1176 | m_pDataWriter.Write(aData[i].x); 1177 | m_pDataWriter.Write(aData[i].y); 1178 | } 1179 | } 1180 | 1181 | /// 1182 | /// 写入数据。 1183 | /// 1184 | /// 1185 | public void WriteData(Vector2 mData) 1186 | { 1187 | m_pDataWriter.Write(mData.x); 1188 | m_pDataWriter.Write(mData.y); 1189 | } 1190 | 1191 | /// 1192 | /// 写入数据。 1193 | /// 1194 | /// 1195 | public void WriteData(Vector3 mData) 1196 | { 1197 | m_pDataWriter.Write(mData.x); 1198 | m_pDataWriter.Write(mData.y); 1199 | m_pDataWriter.Write(mData.z); 1200 | } 1201 | 1202 | /// 1203 | /// 写入数据。 1204 | /// 1205 | /// 1206 | public void WriteData(Quaternion mData) 1207 | { 1208 | m_pDataWriter.Write(mData.x); 1209 | m_pDataWriter.Write(mData.y); 1210 | m_pDataWriter.Write(mData.z); 1211 | m_pDataWriter.Write(mData.w); 1212 | } 1213 | 1214 | /// 1215 | /// 写入数据。 1216 | /// 1217 | /// 1218 | public void WriteData(Color mData) 1219 | { 1220 | m_pDataWriter.Write(mData.r); 1221 | m_pDataWriter.Write(mData.g); 1222 | m_pDataWriter.Write(mData.b); 1223 | m_pDataWriter.Write(mData.a); 1224 | } 1225 | 1226 | /// 1227 | /// 写入数据。 1228 | /// 1229 | /// 1230 | public void WriteData(int nData) 1231 | { 1232 | m_pDataWriter.Write(nData); 1233 | } 1234 | 1235 | /// 1236 | /// 写入数据。 1237 | /// 1238 | /// 1239 | public void WriteData(string pData) 1240 | { 1241 | if (null == pData) 1242 | { 1243 | pData = ""; 1244 | } 1245 | 1246 | byte[] aData = System.Text.ASCIIEncoding.UTF8.GetBytes(pData); 1247 | 1248 | m_pDataWriter.Write(aData.Length); 1249 | m_pDataWriter.Write(aData); 1250 | m_pDataWriter.Write((byte)0); 1251 | } 1252 | 1253 | 1254 | /// 1255 | /// 添加名称地址。 1256 | /// 1257 | /// 1258 | private void AddName(int nAddr) 1259 | { 1260 | if (0 != m_aDesc.Count % 2) 1261 | { 1262 | Debug.LogError("AddName(): 0 != m_aDesc.Count % 2"); 1263 | } 1264 | 1265 | m_aDesc.Add(nAddr); 1266 | } 1267 | 1268 | /// 1269 | /// 添加名称地址。 1270 | /// 1271 | /// 1272 | private void AddData(int nAddr) 1273 | { 1274 | if (1 != m_aDesc.Count % 2) 1275 | { 1276 | Debug.LogError("AddData(): 0 != m_aDesc.Count % 2"); 1277 | } 1278 | 1279 | m_aDesc.Add(nAddr); 1280 | } 1281 | 1282 | 1283 | /// 1284 | /// 查找对象索引。 1285 | /// 1286 | /// 1287 | /// 1288 | public int FindObject(Object pObject) 1289 | { 1290 | if (!m_pDict.ContainsKey(pObject)) 1291 | { 1292 | return -1; 1293 | } 1294 | 1295 | return m_pDict[pObject]; 1296 | } 1297 | 1298 | /// 1299 | /// 添加新对象。 1300 | /// 1301 | /// 1302 | /// 1303 | public int AddObject(Object pObject) 1304 | { 1305 | int nIndex = m_pDict.Count; 1306 | 1307 | m_pDict.Add(pObject, nIndex); 1308 | 1309 | return nIndex; 1310 | } 1311 | 1312 | 1313 | /// 1314 | /// 数据项数据引用描述:[名称地址偏移、数据地址偏移] 1315 | /// 1316 | private List m_aDesc; 1317 | 1318 | /// 1319 | /// 名称数据流对象。 1320 | /// 1321 | private MemoryStream m_pNameStream; 1322 | 1323 | /// 1324 | /// 名称写入器对象。 1325 | /// 1326 | private BinaryWriter m_pNameWriter; 1327 | 1328 | /// 1329 | /// 数据数据流对象。 1330 | /// 1331 | private MemoryStream m_pDataStream; 1332 | 1333 | /// 1334 | /// 数据写入器对象。 1335 | /// 1336 | private BinaryWriter m_pDataWriter; 1337 | 1338 | /// 1339 | /// 对象字典。 1340 | /// 1341 | private Dictionary m_pDict; 1342 | 1343 | 1344 | /// 1345 | /// 头数据总计大小。 1346 | /// 1347 | public static int g_nTotalHeader = 0; 1348 | 1349 | /// 1350 | /// 名称数据总计大小。 1351 | /// 1352 | public static int g_nTotalName = 0; 1353 | } 1354 | #endregion 1355 | } 1356 | -------------------------------------------------------------------------------- /web/public/data/tools/lzma.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/YONGTOC/MiaokitJS/2ff92f29229c99c31eb8fc1935d86888e14114f3/web/public/data/tools/lzma.exe -------------------------------------------------------------------------------- /web/public/gis.html: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | GIS 3D 8 | 9 | 10 | 11 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 |
117 |
    118 |
  • 119 | 120 |
  • 121 |
  • 122 | 123 |
  • 124 |
  • 125 | 126 |
  • 127 |
  • 128 | 129 |
  • 130 |
  • 131 | 132 |
  • 133 |
  • 134 | 135 |
  • 136 |
  • 137 | 138 |
  • 139 |
140 |
    141 |
  • 142 | 143 |
  • 144 |
  • 145 | 146 |
  • 147 |
  • 148 | 149 |
  • 150 |
  • 151 | 152 |
  • 153 |
  • 154 | 155 |
  • 156 |
  • 157 | 158 |
  • 159 |
  • 160 | 161 |
  • 162 |
163 | 164 | --------------------------------------------------------------------------------