├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── _config.yml ├── demo ├── ground.jpg └── index.html ├── dist ├── MeshEditor.d.ts ├── MeshEditor.js ├── MeshEditor.js.map └── MeshEditor.min.js ├── lib ├── EditControl.min.js └── babylon.3.1.1-12-13-2017.js ├── package.json └── src ├── EditControl.d.ts ├── MeshEditor.ts └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | nbproject 2 | node_modules 3 | 4 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | nbproject 2 | node_modules 3 | lib 4 | src 5 | _config.yml 6 | 7 | 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # BabylonJS MeshEditor 2 | 3 | 4 | ## About 5 | 6 | A mesh editor for BabylonJS. 7 | 8 | For Demo see https://ssatguru.github.io/BabylonJS-MeshEditor/demo/index.html 9 | 10 | ## Quick start 11 | 12 | 1) add the following dependencies 13 | ``` 14 | 15 | 16 | 17 | ``` 18 | See INSTALL below to find where you can get "MeshEditor.min.js". 19 | 20 | 2) a small javascript code snippet to get you up and running 21 | ``` 22 | //------------------MeshEditor ------------------------------------------------- 23 | var MeshEditor = org.ssatguru.babylonjs.component.MeshEditor; 24 | var me = new new MeshEditor(mesh,camera,canvas,scene); 25 | me.start(); 26 | ``` 27 | 28 | see index.html in "demo" folder for a working example 29 | [https://github.com/ssatguru/BabylonJS-MeshEditor/blob/master/demo/index.html](https://github.com/ssatguru/BabylonJS-MeshEditor/blob/master/demo/index.html) 30 | 31 | ## INSTALL 32 | 33 | You can get the "MeshEditor.min.js" from its git repository "dist" folder or "releases" section 34 | [https://github.com/ssatguru/BabylonJS-MeshEditor/tree/master/dist](https://github.com/ssatguru/BabylonJS-MeshEditor/tree/master/dist) 35 | [https://github.com/ssatguru/BabylonJS-MeshEditor/releases](https://github.com/ssatguru/BabylonJS-MeshEditor/releases) 36 | 37 | You can also install it from npm (TODO) 38 | ``` 39 | npm install babylonjs-mesheditor 40 | ``` 41 | 42 | Note that even though this is available in npm it is not packaged as a node module or any other type of module. 43 | For now, to keep it simple and avoid dependencies on module systems, the application is packaged as a simple javascript "namespaced" application. 44 | In other words load it using the "script" tag and refer to it using the global name "org.ssatguru.babylonjs.component.MeshEditor". 45 | 46 | ## API 47 | #### To Instantiate 48 | ``` 49 | // JavaScript 50 | var MeshEditor = org.ssatguru.babylonjs.component.MeshEditor; 51 | var me = new new MeshEditor(mesh,camera,canvas,scene); 52 | ``` 53 | ``` 54 | // TypeScript 55 | import MeshEditor = org.ssatguru.babylonjs.component.MeshEditor; 56 | let me = new new MeshEditor(mesh,camera,canvas,scene); 57 | ``` 58 | Takes four parms 59 | * mesh - the mesh to edit 60 | * camera - camera 61 | * canvas - canvas 62 | * scene - scene 63 | 64 | ## Build 65 | If not already installed, install node js and typescript. 66 | Switch to the project folder. 67 | Run "npm install", once, to install all the dependencies (these, for now, are babylonjs, editcontrol, and uglify). 68 | To build anytime 69 | Run "npm run compile" - this will compile the typescript file and store the javascript file in the "dist" folder. 70 | Run "npm run min" - this will minify the javascript file and store the minified version in the "dist" folder. 71 | Run "npm run build" - this will both compile and minify. 72 | Use the "test.html" in demo folder to test your changes. 73 | 74 | 75 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /demo/ground.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ssatguru/BabylonJS-MeshEditor/0d602fa25405f7e57c710134b6a1afe234b3bf4f/demo/ground.jpg -------------------------------------------------------------------------------- /demo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | MeshEditor for BabylonJS 7 | 8 | 9 | 10 | 11 | 12 | 13 | 59 | 60 | 61 | 62 | 63 |
64 | 65 |
66 | 67 |
68 | Key
69 | W : toggle wireframe
70 | F : switch to Face mode
71 | E : switch to Edge mode
72 | P : switch to Point mode
73 | 1 : translate
74 | 2 : rotate
75 | 3 : scale
76 | L : toggle local/global axes
77 | Z : zoom/focus
78 |
79 | Mouse
80 | right click : select face
81 |
82 |
83 |
84 | 85 |
86 |
87 |

Demo of MeshEditor for Babylonjs

88 |

89 | For more information and source code head on over to
90 | 92 | https://github.com/ssatguru/BabylonJS-MeshEditor 93 |

94 | 95 |
96 |
97 | 98 | 206 | 207 | 208 | 209 | 210 | -------------------------------------------------------------------------------- /dist/MeshEditor.d.ts: -------------------------------------------------------------------------------- 1 | declare namespace org.ssatguru.babylonjs.component { 2 | import Camera = BABYLON.Camera; 3 | import IndicesArray = BABYLON.IndicesArray; 4 | import Vector3 = BABYLON.Vector3; 5 | import Mesh = BABYLON.Mesh; 6 | import Scene = BABYLON.Scene; 7 | import EditControl = org.ssatguru.babylonjs.component.EditControl; 8 | class MeshEditor { 9 | camera: Camera; 10 | canvas: HTMLCanvasElement; 11 | scene: Scene; 12 | vertices: number[] | Float32Array; 13 | faceVertices: IndicesArray; 14 | mesh: Mesh; 15 | facePicked: number; 16 | ec: EditControl; 17 | mode: String; 18 | faceSelector: Mesh; 19 | edgeSelector: Mesh; 20 | pointSelector: Mesh; 21 | selectedMesh: Mesh; 22 | enablePoint(): void; 23 | enableEdge(): void; 24 | enableFace(): void; 25 | constructor(mesh: Mesh, camera: Camera, canvas: HTMLCanvasElement, scene: Scene); 26 | private createEditControl(mesh, camera, canvas); 27 | private createFaceSelector_old(scene); 28 | private createFaceSelector(scene); 29 | private createEdgeSelector(scene); 30 | v1v: Vector3; 31 | v2v: Vector3; 32 | v3v: Vector3; 33 | private highLightFace(faceId, faceSelector); 34 | pTemp: Vector3; 35 | private updateFacePosition(faceId, faceSelector); 36 | private highLightEdge(faceId, pickPoint, edgeSelector); 37 | private ep1; 38 | private ep2; 39 | private updateEdgePosition(faceId, edgeSelector); 40 | private p; 41 | private highLightPoint(faceId, pickPoint, pointSelector); 42 | private updatePointPosition(faceId, pointSelector); 43 | private getFaceVertices(faceId, mesh, faceVertices); 44 | private setMaterial(mesh, color, scene); 45 | private clearColors(vrtColors); 46 | private setColor(cc, vrtColors, color); 47 | enableTranslation(): void; 48 | enableRotation(): void; 49 | enableScaling(): void; 50 | setSpaceLocal(): void; 51 | setSpaceWorld(): void; 52 | isLocal(): boolean; 53 | focus(): void; 54 | private createTriangle(name, w, scene); 55 | private getRotation(a1, a2); 56 | private getDistance(p1, p2, p3); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /dist/MeshEditor.js: -------------------------------------------------------------------------------- 1 | var org; 2 | (function (org) { 3 | var ssatguru; 4 | (function (ssatguru) { 5 | var babylonjs; 6 | (function (babylonjs) { 7 | var component; 8 | (function (component) { 9 | var Color3 = BABYLON.Color3; 10 | var Vector3 = BABYLON.Vector3; 11 | var Mesh = BABYLON.Mesh; 12 | var StandardMaterial = BABYLON.StandardMaterial; 13 | var Path2 = BABYLON.Path2; 14 | var VertexBuffer = BABYLON.VertexBuffer; 15 | var EditControl = org.ssatguru.babylonjs.component.EditControl; 16 | var MeshEditor = (function () { 17 | function MeshEditor(mesh, camera, canvas, scene) { 18 | var _this = this; 19 | this.facePicked = 0; 20 | this.ec = null; 21 | this.mode = "F"; 22 | this.v1v = new Vector3(0, 0, 0); 23 | this.v2v = new Vector3(0, 0, 0); 24 | this.v3v = new Vector3(0, 0, 0); 25 | this.pTemp = Vector3.Zero(); 26 | this.mesh = mesh; 27 | this.camera = camera; 28 | this.canvas = canvas; 29 | this.scene = scene; 30 | this.mesh.markVerticesDataAsUpdatable(VertexBuffer.PositionKind, true); 31 | this.vertices = mesh.getVerticesData(VertexBuffer.PositionKind); 32 | this.faceVertices = mesh.getIndices(); 33 | this.faceSelector = this.createFaceSelector(scene); 34 | this.edgeSelector = this.createEdgeSelector(scene); 35 | this.pointSelector = new Mesh("pointSelector", scene); 36 | this.ec = null; 37 | scene.pointerDownPredicate = function (mesh) { 38 | if (mesh == _this.mesh) 39 | return true; 40 | else 41 | return false; 42 | }; 43 | scene.onPointerDown = function (evt, pickResult) { 44 | if (!(evt.button == 2)) 45 | return; 46 | if (pickResult.hit) { 47 | if (pickResult.pickedMesh != _this.mesh) 48 | return; 49 | _this.facePicked = pickResult.faceId; 50 | var selector = null; 51 | if (_this.mode == "F") { 52 | selector = _this.faceSelector; 53 | _this.highLightFace(_this.facePicked, selector); 54 | } 55 | else if (_this.mode == "E") { 56 | selector = _this.edgeSelector; 57 | _this.highLightEdge(_this.facePicked, pickResult.pickedPoint, selector); 58 | } 59 | else if (_this.mode == "P") { 60 | selector = _this.pointSelector; 61 | _this.highLightPoint(_this.facePicked, pickResult.pickedPoint, selector); 62 | } 63 | if (selector != null) { 64 | selector.visibility = 1; 65 | if (_this.ec == null) { 66 | _this.ec = _this.createEditControl(selector, _this.camera, _this.canvas); 67 | } 68 | else { 69 | if (_this.ec.isHidden()) 70 | _this.ec.show(); 71 | _this.ec.switchTo(selector, true); 72 | } 73 | } 74 | } 75 | }; 76 | } 77 | MeshEditor.prototype.enablePoint = function () { 78 | if (this.mode == "P") 79 | return; 80 | this.mode = "P"; 81 | this.faceSelector.visibility = 0; 82 | this.edgeSelector.visibility = 0; 83 | this.ec.hide(); 84 | }; 85 | MeshEditor.prototype.enableEdge = function () { 86 | if (this.mode == "E") 87 | return; 88 | this.mode = "E"; 89 | this.faceSelector.visibility = 0; 90 | this.pointSelector.visibility = 0; 91 | this.ec.hide(); 92 | }; 93 | MeshEditor.prototype.enableFace = function () { 94 | if (this.mode == "F") 95 | return; 96 | this.mode = "F"; 97 | this.edgeSelector.visibility = 0; 98 | this.pointSelector.visibility = 0; 99 | this.ec.hide(); 100 | }; 101 | MeshEditor.prototype.createEditControl = function (mesh, camera, canvas) { 102 | var _this = this; 103 | var ec = new EditControl(mesh, camera, canvas, 0.75, true); 104 | ec.setLocal(true); 105 | ec.enableTranslation(); 106 | ec.addActionListener(function (t) { 107 | if (_this.mode == "F") { 108 | _this.updateFacePosition(_this.facePicked, _this.faceSelector); 109 | } 110 | else if (_this.mode == "E") { 111 | _this.updateEdgePosition(_this.facePicked, _this.edgeSelector); 112 | } 113 | else if (_this.mode == "P") { 114 | _this.updatePointPosition(_this.facePicked, _this.pointSelector); 115 | } 116 | _this.mesh.updateVerticesData(VertexBuffer.PositionKind, _this.vertices, false, false); 117 | }); 118 | return ec; 119 | }; 120 | MeshEditor.prototype.createFaceSelector_old = function (scene) { 121 | var fs = this.createTriangle("selector", 1, scene); 122 | fs.material = new StandardMaterial("impactMat", scene); 123 | fs.material.diffuseColor = Color3.Gray(); 124 | fs.visibility = 0.8; 125 | fs.markVerticesDataAsUpdatable(VertexBuffer.PositionKind, true); 126 | fs.renderingGroupId = 1; 127 | return fs; 128 | }; 129 | MeshEditor.prototype.createFaceSelector = function (scene) { 130 | var fs = Mesh.CreateLines("edgeSelector", [new Vector3(-1, 0, 0), new Vector3(1, 0, 0), new Vector3(0, 0, 1), new Vector3(-1, 0, 0)], scene); 131 | fs.color = Color3.Black(); 132 | fs.visibility = 0; 133 | fs.markVerticesDataAsUpdatable(VertexBuffer.PositionKind, true); 134 | fs.renderingGroupId = 1; 135 | return fs; 136 | }; 137 | MeshEditor.prototype.createEdgeSelector = function (scene) { 138 | var es = Mesh.CreateLines("edgeSelector", [new Vector3(-1, 0, 0), new Vector3(1, 0, 0)], scene); 139 | es.color = Color3.Black(); 140 | es.isPickable = false; 141 | es.renderingGroupId = 1; 142 | es.visibility = 0; 143 | es.markVerticesDataAsUpdatable(VertexBuffer.PositionKind, true); 144 | return es; 145 | }; 146 | MeshEditor.prototype.highLightFace = function (faceId, faceSelector) { 147 | this.getFaceVertices(faceId, this.mesh, this.faceVertices); 148 | var a1 = this.v1v.subtract(this.v2v); 149 | var a2 = this.v3v.subtract(this.v2v); 150 | faceSelector.rotation = this.getRotation(a1, a2); 151 | faceSelector.position.x = (this.v1v.x + this.v2v.x + this.v3v.x) / 3; 152 | faceSelector.position.y = (this.v1v.y + this.v2v.y + this.v3v.y) / 3; 153 | faceSelector.position.z = (this.v1v.z + this.v2v.z + this.v3v.z) / 3; 154 | var verts = faceSelector.getVerticesData(VertexBuffer.PositionKind); 155 | var sm_i = faceSelector.getWorldMatrix().clone().invert(); 156 | Vector3.TransformCoordinatesToRef(this.v1v, sm_i, this.pTemp); 157 | verts[0] = this.pTemp.x; 158 | verts[1] = this.pTemp.y; 159 | verts[2] = this.pTemp.z; 160 | Vector3.TransformCoordinatesToRef(this.v2v, sm_i, this.pTemp); 161 | verts[3] = this.pTemp.x; 162 | verts[4] = this.pTemp.y; 163 | verts[5] = this.pTemp.z; 164 | Vector3.TransformCoordinatesToRef(this.v3v, sm_i, this.pTemp); 165 | verts[6] = this.pTemp.x; 166 | verts[7] = this.pTemp.y; 167 | verts[8] = this.pTemp.z; 168 | verts[9] = verts[0]; 169 | verts[10] = verts[1]; 170 | verts[11] = verts[2]; 171 | faceSelector.setVerticesData(VertexBuffer.PositionKind, verts, true); 172 | }; 173 | MeshEditor.prototype.updateFacePosition = function (faceId, faceSelector) { 174 | var i = faceId * 3; 175 | var v1 = this.faceVertices[i]; 176 | var v2 = this.faceVertices[i + 1]; 177 | var v3 = this.faceVertices[i + 2]; 178 | var v = this.vertices; 179 | var v1s = v1 * 3; 180 | var v2s = v2 * 3; 181 | var v3s = v3 * 3; 182 | var verts = faceSelector.getVerticesData(VertexBuffer.PositionKind); 183 | var sm = faceSelector.getWorldMatrix(); 184 | var mm_i = this.mesh.getWorldMatrix().clone().invert(); 185 | Vector3.TransformCoordinatesFromFloatsToRef(verts[0], verts[1], verts[2], sm, this.pTemp); 186 | Vector3.TransformCoordinatesFromFloatsToRef(this.pTemp.x, this.pTemp.y, this.pTemp.z, mm_i, this.pTemp); 187 | v[v1s] = this.pTemp.x; 188 | v[v1s + 1] = this.pTemp.y; 189 | v[v1s + 2] = this.pTemp.z; 190 | Vector3.TransformCoordinatesFromFloatsToRef(verts[3], verts[4], verts[5], sm, this.pTemp); 191 | Vector3.TransformCoordinatesFromFloatsToRef(this.pTemp.x, this.pTemp.y, this.pTemp.z, mm_i, this.pTemp); 192 | v[v2s] = this.pTemp.x; 193 | v[v2s + 1] = this.pTemp.y; 194 | v[v2s + 2] = this.pTemp.z; 195 | Vector3.TransformCoordinatesFromFloatsToRef(verts[6], verts[7], verts[8], sm, this.pTemp); 196 | Vector3.TransformCoordinatesFromFloatsToRef(this.pTemp.x, this.pTemp.y, this.pTemp.z, mm_i, this.pTemp); 197 | v[v3s] = this.pTemp.x; 198 | v[v3s + 1] = this.pTemp.y; 199 | v[v3s + 2] = this.pTemp.z; 200 | }; 201 | ; 202 | MeshEditor.prototype.highLightEdge = function (faceId, pickPoint, edgeSelector) { 203 | this.getFaceVertices(faceId, this.mesh, this.faceVertices); 204 | var ev1; 205 | var ev2; 206 | var ev3; 207 | var h1 = this.getDistance(pickPoint, this.v1v, this.v2v); 208 | var h2 = this.getDistance(pickPoint, this.v2v, this.v3v); 209 | var h3 = this.getDistance(pickPoint, this.v3v, this.v1v); 210 | var min_h = Math.min(h1, h2, h3); 211 | if (min_h == h1) { 212 | ev1 = this.v1v; 213 | ev2 = this.v2v; 214 | ev3 = this.v3v; 215 | this.ep1 = 1; 216 | this.ep2 = 2; 217 | } 218 | if (min_h == h2) { 219 | ev1 = this.v2v; 220 | ev2 = this.v3v; 221 | ev3 = this.v1v; 222 | this.ep1 = 2; 223 | this.ep2 = 3; 224 | } 225 | if (min_h == h3) { 226 | ev1 = this.v3v; 227 | ev2 = this.v1v; 228 | ev3 = this.v2v; 229 | this.ep1 = 3; 230 | this.ep2 = 1; 231 | } 232 | var a1 = ev1.subtract(ev2); 233 | var a2 = ev3.subtract(ev2); 234 | edgeSelector.rotation = this.getRotation(a1, a2); 235 | edgeSelector.position.x = (ev1.x + ev2.x) / 2; 236 | edgeSelector.position.y = (ev1.y + ev2.y) / 2; 237 | edgeSelector.position.z = (ev1.z + ev2.z) / 2; 238 | var verts = edgeSelector.getVerticesData(VertexBuffer.PositionKind); 239 | var sm_i = edgeSelector.getWorldMatrix().clone().invert(); 240 | Vector3.TransformCoordinatesToRef(ev1, sm_i, this.pTemp); 241 | verts[0] = this.pTemp.x; 242 | verts[1] = this.pTemp.y; 243 | verts[2] = this.pTemp.z; 244 | Vector3.TransformCoordinatesToRef(ev2, sm_i, this.pTemp); 245 | verts[3] = this.pTemp.x; 246 | verts[4] = this.pTemp.y; 247 | verts[5] = this.pTemp.z; 248 | edgeSelector.setVerticesData(VertexBuffer.PositionKind, verts, true); 249 | this.ec.switchTo(edgeSelector, true); 250 | }; 251 | MeshEditor.prototype.updateEdgePosition = function (faceId, edgeSelector) { 252 | var i = faceId * 3; 253 | var v1 = this.faceVertices[i + this.ep1 - 1]; 254 | var v2 = this.faceVertices[i + this.ep2 - 1]; 255 | var v = this.vertices; 256 | var v1s = v1 * 3; 257 | var v2s = v2 * 3; 258 | var verts = edgeSelector.getVerticesData(VertexBuffer.PositionKind); 259 | var sm = edgeSelector.getWorldMatrix(); 260 | var mm_i = this.mesh.getWorldMatrix().clone().invert(); 261 | Vector3.TransformCoordinatesFromFloatsToRef(verts[0], verts[1], verts[2], sm, this.pTemp); 262 | Vector3.TransformCoordinatesFromFloatsToRef(this.pTemp.x, this.pTemp.y, this.pTemp.z, mm_i, this.pTemp); 263 | v[v1s] = this.pTemp.x; 264 | v[v1s + 1] = this.pTemp.y; 265 | v[v1s + 2] = this.pTemp.z; 266 | Vector3.TransformCoordinatesFromFloatsToRef(verts[3], verts[4], verts[5], sm, this.pTemp); 267 | Vector3.TransformCoordinatesFromFloatsToRef(this.pTemp.x, this.pTemp.y, this.pTemp.z, mm_i, this.pTemp); 268 | v[v2s] = this.pTemp.x; 269 | v[v2s + 1] = this.pTemp.y; 270 | v[v2s + 2] = this.pTemp.z; 271 | }; 272 | ; 273 | MeshEditor.prototype.highLightPoint = function (faceId, pickPoint, pointSelector) { 274 | this.getFaceVertices(faceId, this.mesh, this.faceVertices); 275 | var p1; 276 | var p2; 277 | var p3; 278 | var l1 = pickPoint.subtract(this.v1v).length(); 279 | var l2 = pickPoint.subtract(this.v2v).length(); 280 | var l3 = pickPoint.subtract(this.v3v).length(); 281 | var min_l = Math.min(l1, l2, l3); 282 | if (min_l == l1) { 283 | this.p = 1; 284 | p1 = this.v1v; 285 | p2 = this.v3v; 286 | p3 = this.v2v; 287 | } 288 | if (min_l == l2) { 289 | this.p = 2; 290 | p1 = this.v2v; 291 | p2 = this.v1v; 292 | p3 = this.v3v; 293 | } 294 | if (min_l == l3) { 295 | this.p = 3; 296 | p1 = this.v3v; 297 | p2 = this.v2v; 298 | p3 = this.v1v; 299 | } 300 | var a1 = p2.subtract(p1); 301 | var a2 = p3.subtract(p1); 302 | pointSelector.rotation = this.getRotation(a1, a2); 303 | pointSelector.position = p1; 304 | this.ec.switchTo(pointSelector, true); 305 | }; 306 | MeshEditor.prototype.updatePointPosition = function (faceId, pointSelector) { 307 | var i = faceId * 3; 308 | var v1 = this.faceVertices[i + this.p - 1]; 309 | var v = this.vertices; 310 | var v1s = v1 * 3; 311 | var mm_i = this.mesh.getWorldMatrix().clone().invert(); 312 | Vector3.TransformCoordinatesToRef(pointSelector.position, mm_i, this.pTemp); 313 | v[v1s] = this.pTemp.x; 314 | v[v1s + 1] = this.pTemp.y; 315 | v[v1s + 2] = this.pTemp.z; 316 | }; 317 | ; 318 | MeshEditor.prototype.getFaceVertices = function (faceId, mesh, faceVertices) { 319 | var i = faceId * 3; 320 | var v1 = faceVertices[i]; 321 | var v2 = faceVertices[i + 1]; 322 | var v3 = faceVertices[i + 2]; 323 | var mm = mesh.getWorldMatrix(); 324 | var v = this.vertices; 325 | var v1s = v1 * 3; 326 | var v2s = v2 * 3; 327 | var v3s = v3 * 3; 328 | Vector3.TransformCoordinatesFromFloatsToRef(v[v1s], v[v1s + 1], v[v1s + 2], mm, this.v1v); 329 | Vector3.TransformCoordinatesFromFloatsToRef(v[v2s], v[v2s + 1], v[v2s + 2], mm, this.v2v); 330 | Vector3.TransformCoordinatesFromFloatsToRef(v[v3s], v[v3s + 1], v[v3s + 2], mm, this.v3v); 331 | }; 332 | MeshEditor.prototype.setMaterial = function (mesh, color, scene) { 333 | mesh.material = new StandardMaterial("", scene); 334 | mesh.material.diffuseColor = color; 335 | }; 336 | MeshEditor.prototype.clearColors = function (vrtColors) { 337 | var j = vrtColors.length - 3; 338 | for (var i = 0; i < j; i = i + 4) { 339 | vrtColors[i] = 1; 340 | vrtColors[i + 1] = 1; 341 | vrtColors[i + 2] = 1; 342 | vrtColors[i + 3] = 1; 343 | } 344 | }; 345 | MeshEditor.prototype.setColor = function (cc, vrtColors, color) { 346 | vrtColors[cc] = color.r; 347 | vrtColors[cc + 1] = color.g; 348 | vrtColors[cc + 2] = color.b; 349 | vrtColors[cc + 3] = 0; 350 | }; 351 | MeshEditor.prototype.enableTranslation = function () { 352 | if (this.ec != null) 353 | this.ec.enableTranslation(); 354 | }; 355 | MeshEditor.prototype.enableRotation = function () { 356 | if (this.ec != null) 357 | this.ec.enableRotation(); 358 | }; 359 | MeshEditor.prototype.enableScaling = function () { 360 | if (this.ec != null) { 361 | this.ec.enableScaling(); 362 | if (!this.ec.isLocal()) 363 | this.ec.setLocal(true); 364 | } 365 | }; 366 | MeshEditor.prototype.setSpaceLocal = function () { 367 | this.ec.setLocal(true); 368 | }; 369 | MeshEditor.prototype.setSpaceWorld = function () { 370 | this.ec.setLocal(false); 371 | }; 372 | MeshEditor.prototype.isLocal = function () { 373 | return this.ec.isLocal(); 374 | }; 375 | MeshEditor.prototype.focus = function () { 376 | if (this.ec != null) 377 | this.camera.target = this.ec.getPosition(); 378 | }; 379 | MeshEditor.prototype.createTriangle = function (name, w, scene) { 380 | var p = new Path2(w / 2, -w / 2).addLineTo(w / 2, w / 2).addLineTo(-w / 2, w / 2).addLineTo(w / 2, -w / 2); 381 | var s = new BABYLON.PolygonMeshBuilder(name, p, scene); 382 | var t = s.build(true); 383 | return t; 384 | }; 385 | MeshEditor.prototype.getRotation = function (a1, a2) { 386 | Vector3.CrossToRef(a1, a2, this.pTemp); 387 | var a3 = Vector3.Cross(this.pTemp, a1); 388 | return Vector3.RotationFromAxis(a3, this.pTemp, a1); 389 | }; 390 | MeshEditor.prototype.getDistance = function (p1, p2, p3) { 391 | var v1 = p1.subtract(p2); 392 | var v2 = p3.subtract(p2); 393 | var angle = Math.acos((Vector3.Dot(v1, v2.normalize()) / v1.length())); 394 | return v1.length() * Math.sin(angle); 395 | }; 396 | return MeshEditor; 397 | }()); 398 | component.MeshEditor = MeshEditor; 399 | })(component = babylonjs.component || (babylonjs.component = {})); 400 | })(babylonjs = ssatguru.babylonjs || (ssatguru.babylonjs = {})); 401 | })(ssatguru = org.ssatguru || (org.ssatguru = {})); 402 | })(org || (org = {})); 403 | //# sourceMappingURL=MeshEditor.js.map -------------------------------------------------------------------------------- /dist/MeshEditor.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"MeshEditor.js","sourceRoot":"","sources":["../src/MeshEditor.ts"],"names":[],"mappings":"AACA,IAAU,GAAG,CAogBZ;AApgBD,WAAU,GAAG;IAAC,IAAA,QAAQ,CAogBrB;IApgBa,WAAA,QAAQ;QAAC,IAAA,SAAS,CAogB/B;QApgBsB,WAAA,SAAS;YAAC,IAAA,SAAS,CAogBzC;YApgBgC,WAAA,SAAS;gBAItC,IAAO,MAAM,GAAC,OAAO,CAAC,MAAM,CAAC;gBAG7B,IAAO,OAAO,GAAC,OAAO,CAAC,OAAO,CAAC;gBAG/B,IAAO,IAAI,GAAC,OAAO,CAAC,IAAI,CAAC;gBAEzB,IAAO,gBAAgB,GAAC,OAAO,CAAC,gBAAgB,CAAC;gBAEjD,IAAO,KAAK,GAAC,OAAO,CAAC,KAAK,CAAC;gBAE3B,IAAO,YAAY,GAAC,OAAO,CAAC,YAAY,CAAC;gBACzC,IAAO,WAAW,GAAC,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,WAAW,CAAC;gBAEhE;oBA2CI,oBAAY,IAAU,EAAC,MAAc,EAAC,MAAyB,EAAC,KAAY;wBAA5E,iBAgEC;wBAlGD,eAAU,GAAS,CAAC,CAAC;wBACrB,OAAE,GAAc,IAAI,CAAC;wBAErB,SAAI,GAAS,GAAG,CAAC;wBA6IjB,QAAG,GAAU,IAAI,OAAO,CAA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AC,QAAQ,CAAC,EAAE,CAAC,CAAC;wBAEhC,IAAI,KAAK,GAAS,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,EAAC,EAAE,CAAC,SAAS,EAAE,CAAC,GAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;wBAC1E,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,GAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;oBAGvC,CAAC;oBAEL,iBAAC;gBAAD,CAAC,AAhfD,IAgfC;gBAhfY,oBAAU,aAgftB,CAAA;YACL,CAAC,EApgBgC,SAAS,GAAT,mBAAS,KAAT,mBAAS,QAogBzC;QAAD,CAAC,EApgBsB,SAAS,GAAT,kBAAS,KAAT,kBAAS,QAogB/B;IAAD,CAAC,EApgBa,QAAQ,GAAR,YAAQ,KAAR,YAAQ,QAogBrB;AAAD,CAAC,EApgBS,GAAG,KAAH,GAAG,QAogBZ"} -------------------------------------------------------------------------------- /dist/MeshEditor.min.js: -------------------------------------------------------------------------------- 1 | var org;!function(t){!function(e){!function(e){!function(e){var i=BABYLON.Color3,s=BABYLON.Vector3,o=BABYLON.Mesh,r=BABYLON.StandardMaterial,n=BABYLON.Path2,a=BABYLON.VertexBuffer,h=t.ssatguru.babylonjs.component.EditControl,p=function(){function t(t,e,i,r){var n=this;this.facePicked=0,this.ec=null,this.mode="F",this.v1v=new s(0,0,0),this.v2v=new s(0,0,0),this.v3v=new s(0,0,0),this.pTemp=s.Zero(),this.mesh=t,this.camera=e,this.canvas=i,this.scene=r,this.mesh.markVerticesDataAsUpdatable(a.PositionKind,!0),this.vertices=t.getVerticesData(a.PositionKind),this.faceVertices=t.getIndices(),this.faceSelector=this.createFaceSelector(r),this.edgeSelector=this.createEdgeSelector(r),this.pointSelector=new o("pointSelector",r),this.ec=null,r.pointerDownPredicate=function(t){return t==n.mesh},r.onPointerDown=function(t,e){if(2==t.button&&e.hit){if(e.pickedMesh!=n.mesh)return;n.facePicked=e.faceId;var i=null;"F"==n.mode?(i=n.faceSelector,n.highLightFace(n.facePicked,i)):"E"==n.mode?(i=n.edgeSelector,n.highLightEdge(n.facePicked,e.pickedPoint,i)):"P"==n.mode&&(i=n.pointSelector,n.highLightPoint(n.facePicked,e.pickedPoint,i)),null!=i&&(i.visibility=1,null==n.ec?n.ec=n.createEditControl(i,n.camera,n.canvas):(n.ec.isHidden()&&n.ec.show(),n.ec.switchTo(i,!0)))}}}return t.prototype.enablePoint=function(){"P"!=this.mode&&(this.mode="P",this.faceSelector.visibility=0,this.edgeSelector.visibility=0,this.ec.hide())},t.prototype.enableEdge=function(){"E"!=this.mode&&(this.mode="E",this.faceSelector.visibility=0,this.pointSelector.visibility=0,this.ec.hide())},t.prototype.enableFace=function(){"F"!=this.mode&&(this.mode="F",this.edgeSelector.visibility=0,this.pointSelector.visibility=0,this.ec.hide())},t.prototype.createEditControl=function(t,e,i){var s=this,o=new h(t,e,i,.75,!0);return o.setLocal(!0),o.enableTranslation(),o.addActionListener(function(t){"F"==s.mode?s.updateFacePosition(s.facePicked,s.faceSelector):"E"==s.mode?s.updateEdgePosition(s.facePicked,s.edgeSelector):"P"==s.mode&&s.updatePointPosition(s.facePicked,s.pointSelector),s.mesh.updateVerticesData(a.PositionKind,s.vertices,!1,!1)}),o},t.prototype.createFaceSelector_old=function(t){var e=this.createTriangle("selector",1,t);return e.material=new r("impactMat",t),e.material.diffuseColor=i.Gray(),e.visibility=.8,e.markVerticesDataAsUpdatable(a.PositionKind,!0),e.renderingGroupId=1,e},t.prototype.createFaceSelector=function(t){var e=o.CreateLines("edgeSelector",[new s(-1,0,0),new s(1,0,0),new s(0,0,1),new s(-1,0,0)],t);return e.color=i.Black(),e.visibility=0,e.markVerticesDataAsUpdatable(a.PositionKind,!0),e.renderingGroupId=1,e},t.prototype.createEdgeSelector=function(t){var e=o.CreateLines("edgeSelector",[new s(-1,0,0),new s(1,0,0)],t);return e.color=i.Black(),e.isPickable=!1,e.renderingGroupId=1,e.visibility=0,e.markVerticesDataAsUpdatable(a.PositionKind,!0),e},t.prototype.highLightFace=function(t,e){this.getFaceVertices(t,this.mesh,this.faceVertices);var i=this.v1v.subtract(this.v2v),o=this.v3v.subtract(this.v2v);e.rotation=this.getRotation(i,o),e.position.x=(this.v1v.x+this.v2v.x+this.v3v.x)/3,e.position.y=(this.v1v.y+this.v2v.y+this.v3v.y)/3,e.position.z=(this.v1v.z+this.v2v.z+this.v3v.z)/3;var r=e.getVerticesData(a.PositionKind),n=e.getWorldMatrix().clone().invert();s.TransformCoordinatesToRef(this.v1v,n,this.pTemp),r[0]=this.pTemp.x,r[1]=this.pTemp.y,r[2]=this.pTemp.z,s.TransformCoordinatesToRef(this.v2v,n,this.pTemp),r[3]=this.pTemp.x,r[4]=this.pTemp.y,r[5]=this.pTemp.z,s.TransformCoordinatesToRef(this.v3v,n,this.pTemp),r[6]=this.pTemp.x,r[7]=this.pTemp.y,r[8]=this.pTemp.z,r[9]=r[0],r[10]=r[1],r[11]=r[2],e.setVerticesData(a.PositionKind,r,!0)},t.prototype.updateFacePosition=function(t,e){var i=3*t,o=this.faceVertices[i],r=this.faceVertices[i+1],n=this.faceVertices[i+2],h=this.vertices,p=3*o,c=3*r,v=3*n,m=e.getVerticesData(a.PositionKind),l=e.getWorldMatrix(),d=this.mesh.getWorldMatrix().clone().invert();s.TransformCoordinatesFromFloatsToRef(m[0],m[1],m[2],l,this.pTemp),s.TransformCoordinatesFromFloatsToRef(this.pTemp.x,this.pTemp.y,this.pTemp.z,d,this.pTemp),h[p]=this.pTemp.x,h[p+1]=this.pTemp.y,h[p+2]=this.pTemp.z,s.TransformCoordinatesFromFloatsToRef(m[3],m[4],m[5],l,this.pTemp),s.TransformCoordinatesFromFloatsToRef(this.pTemp.x,this.pTemp.y,this.pTemp.z,d,this.pTemp),h[c]=this.pTemp.x,h[c+1]=this.pTemp.y,h[c+2]=this.pTemp.z,s.TransformCoordinatesFromFloatsToRef(m[6],m[7],m[8],l,this.pTemp),s.TransformCoordinatesFromFloatsToRef(this.pTemp.x,this.pTemp.y,this.pTemp.z,d,this.pTemp),h[v]=this.pTemp.x,h[v+1]=this.pTemp.y,h[v+2]=this.pTemp.z},t.prototype.highLightEdge=function(t,e,i){this.getFaceVertices(t,this.mesh,this.faceVertices);var o,r,n,h=this.getDistance(e,this.v1v,this.v2v),p=this.getDistance(e,this.v2v,this.v3v),c=this.getDistance(e,this.v3v,this.v1v),v=Math.min(h,p,c);v==h&&(o=this.v1v,r=this.v2v,n=this.v3v,this.ep1=1,this.ep2=2),v==p&&(o=this.v2v,r=this.v3v,n=this.v1v,this.ep1=2,this.ep2=3),v==c&&(o=this.v3v,r=this.v1v,n=this.v2v,this.ep1=3,this.ep2=1);var m=o.subtract(r),l=n.subtract(r);i.rotation=this.getRotation(m,l),i.position.x=(o.x+r.x)/2,i.position.y=(o.y+r.y)/2,i.position.z=(o.z+r.z)/2;var d=i.getVerticesData(a.PositionKind),T=i.getWorldMatrix().clone().invert();s.TransformCoordinatesToRef(o,T,this.pTemp),d[0]=this.pTemp.x,d[1]=this.pTemp.y,d[2]=this.pTemp.z,s.TransformCoordinatesToRef(r,T,this.pTemp),d[3]=this.pTemp.x,d[4]=this.pTemp.y,d[5]=this.pTemp.z,i.setVerticesData(a.PositionKind,d,!0),this.ec.switchTo(i,!0)},t.prototype.updateEdgePosition=function(t,e){var i=3*t,o=this.faceVertices[i+this.ep1-1],r=this.faceVertices[i+this.ep2-1],n=this.vertices,h=3*o,p=3*r,c=e.getVerticesData(a.PositionKind),v=e.getWorldMatrix(),m=this.mesh.getWorldMatrix().clone().invert();s.TransformCoordinatesFromFloatsToRef(c[0],c[1],c[2],v,this.pTemp),s.TransformCoordinatesFromFloatsToRef(this.pTemp.x,this.pTemp.y,this.pTemp.z,m,this.pTemp),n[h]=this.pTemp.x,n[h+1]=this.pTemp.y,n[h+2]=this.pTemp.z,s.TransformCoordinatesFromFloatsToRef(c[3],c[4],c[5],v,this.pTemp),s.TransformCoordinatesFromFloatsToRef(this.pTemp.x,this.pTemp.y,this.pTemp.z,m,this.pTemp),n[p]=this.pTemp.x,n[p+1]=this.pTemp.y,n[p+2]=this.pTemp.z},t.prototype.highLightPoint=function(t,e,i){this.getFaceVertices(t,this.mesh,this.faceVertices);var s,o,r,n=e.subtract(this.v1v).length(),a=e.subtract(this.v2v).length(),h=e.subtract(this.v3v).length(),p=Math.min(n,a,h);p==n&&(this.p=1,s=this.v1v,o=this.v3v,r=this.v2v),p==a&&(this.p=2,s=this.v2v,o=this.v1v,r=this.v3v),p==h&&(this.p=3,s=this.v3v,o=this.v2v,r=this.v1v);var c=o.subtract(s),v=r.subtract(s);i.rotation=this.getRotation(c,v),i.position=s,this.ec.switchTo(i,!0)},t.prototype.updatePointPosition=function(t,e){var i=3*t,o=this.faceVertices[i+this.p-1],r=this.vertices,n=3*o,a=this.mesh.getWorldMatrix().clone().invert();s.TransformCoordinatesToRef(e.position,a,this.pTemp),r[n]=this.pTemp.x,r[n+1]=this.pTemp.y,r[n+2]=this.pTemp.z},t.prototype.getFaceVertices=function(t,e,i){var o=3*t,r=i[o],n=i[o+1],a=i[o+2],h=e.getWorldMatrix(),p=this.vertices,c=3*r,v=3*n,m=3*a;s.TransformCoordinatesFromFloatsToRef(p[c],p[c+1],p[c+2],h,this.v1v),s.TransformCoordinatesFromFloatsToRef(p[v],p[v+1],p[v+2],h,this.v2v),s.TransformCoordinatesFromFloatsToRef(p[m],p[m+1],p[m+2],h,this.v3v)},t.prototype.setMaterial=function(t,e,i){t.material=new r("",i),t.material.diffuseColor=e},t.prototype.clearColors=function(t){for(var e=t.length-3,i=0;i=0?this.rX.rotation.x=-t:this.rX.rotation.x=-t-Math.PI;var i=Math.atan(this.ecTOcamera.x/this.ecTOcamera.z);this.ecTOcamera.z>=0?this.rY.rotation.y=i:this.rY.rotation.y=i+Math.PI;var s=Math.atan(this.ecTOcamera.x/this.ecTOcamera.y);this.ecTOcamera.y>=0?this.rZ.rotation.z=-s:this.rZ.rotation.z=-s-Math.PI},t.prototype.renderLoopProcess=function(){this.ecRoot.position=this.mesh.getAbsolutePivotPoint(),this.setAxesScale(),this.setAxesRotation(),this.rotEnabled&&this.rotRotGuides()},t.prototype.switchTo=function(t,i){t.computeWorldMatrix(!0),this.mesh=t,null!=i&&(this.eulerian=i),this.checkQuaternion(),this.setLocalAxes(t),this.actHist=new u(t,10)},t.prototype.setUndoCount=function(t){this.actHist.setCapacity(t)},t.prototype.undo=function(){var t=this.actHist.undo();this.mesh.computeWorldMatrix(!0),this.setLocalAxes(this.mesh),this.callActionStartListener(t),this.callActionListener(t),this.callActionEndListener(t)},t.prototype.redo=function(){var t=this.actHist.redo();this.mesh.computeWorldMatrix(!0),this.setLocalAxes(this.mesh),this.callActionStartListener(t),this.callActionListener(t),this.callActionEndListener(t)},t.prototype.detach=function(){this.canvas.removeEventListener("pointerdown",this.pointerdown,!1),this.canvas.removeEventListener("pointerup",this.pointerup,!1),this.canvas.removeEventListener("pointermove",this.pointermove,!1),this.scene.unregisterBeforeRender(this.renderer),this.removeAllActionListeners(),this.disposeAll()},t.prototype.hide=function(){this.hidden=!0,this.transEnabled?(this.prevState="T",this.disableTranslation()):this.rotEnabled?(this.prevState="R",this.disableRotation()):this.scaleEnabled&&(this.prevState="S",this.disableScaling()),this.hideCommonAxes()},t.prototype.hideCommonAxes=function(){this.xaxis.visibility=0,this.yaxis.visibility=0,this.zaxis.visibility=0},t.prototype.showCommonAxes=function(){this.xaxis.visibility=this.visibility,this.yaxis.visibility=this.visibility,this.zaxis.visibility=this.visibility},t.prototype.show=function(){this.hidden=!1,this.showCommonAxes(),"T"==this.prevState?this.enableTranslation():"R"==this.prevState?this.enableRotation():"S"==this.prevState&&this.enableScaling()},t.prototype.isHidden=function(){return this.hidden},t.prototype.disposeAll=function(){this.ecRoot.dispose(),this.disposeMaterials(),this.actHist=null},t.prototype.addActionListener=function(t){this.actionListener=t},t.prototype.removeActionListener=function(){this.actionListener=null},t.prototype.addActionStartListener=function(t){this.actionStartListener=t},t.prototype.removeActionStartListener=function(){this.actionStartListener=null},t.prototype.addActionEndListener=function(t){this.actionEndListener=t},t.prototype.removeActionEndListener=function(){this.actionEndListener=null},t.prototype.removeAllActionListeners=function(){this.actionListener=null,this.actionStartListener=null,this.actionEndListener=null},t.prototype.onPointerDown=function(t){var i=this;if(t.preventDefault(),this.pDown=!0,0==t.button){var s=this.scene.pick(this.scene.pointerX,this.scene.pointerY,function(t){if(i.transEnabled){if(t==i.tX||t==i.tY||t==i.tZ||t==i.tXZ||t==i.tZY||t==i.tYX||t==i.tAll)return!0}else if(i.rotEnabled){if(t==i.rX||t==i.rY||t==i.rZ||t==i.rAll)return!0}else if(i.scaleEnabled&&(t==i.sX||t==i.sY||t==i.sZ||t==i.sXZ||t==i.sZY||t==i.sYX||t==i.sAll))return!0;return!1},null,this.mainCamera);if(s.hit){this.axisPicked=s.pickedMesh;var e=this.axisPicked.getChildren();e.length>0?e[0].visibility=this.visibility:this.axisPicked.visibility=this.visibility;var n=this.axisPicked.name;"X"==n?this.bXaxis.visibility=1:"Y"==n?this.bYaxis.visibility=1:"Z"==n?this.bZaxis.visibility=1:"XZ"==n?(this.bXaxis.visibility=1,this.bZaxis.visibility=1):"ZY"==n?(this.bZaxis.visibility=1,this.bYaxis.visibility=1):"YX"==n?(this.bYaxis.visibility=1,this.bXaxis.visibility=1):"ALL"==n&&(this.bXaxis.visibility=1,this.bYaxis.visibility=1,this.bZaxis.visibility=1),this.setEditing(!0),this.pickedPlane=this.getPickPlane(this.axisPicked),null!=this.pickedPlane?this.prevPos=this.getPosOnPickPlane():this.prevPos=null,window.setTimeout(function(t,s){return i.detachCamera(t,s)},0,this.mainCamera,this.canvas)}}},t.prototype.setEditing=function(t){this.editing=t,t?(this.setActionType(),this.callActionStartListener(this.actionType)):this.callActionEndListener(this.actionType)},t.prototype.isEditing=function(){return this.editing},t.prototype.detachCamera=function(t,i){var s=t,e=i;s.detachControl(e)},t.prototype.isPointerOver=function(){return this.pointerIsOver},t.prototype.onPointerOver=function(){var t=this,i=this.scene.pick(this.scene.pointerX,this.scene.pointerY,function(i){if(t.transEnabled){if(i==t.tX||i==t.tY||i==t.tZ||i==t.tXZ||i==t.tZY||i==t.tYX||i==t.tAll)return!0}else if(t.rotEnabled){if(i==t.rX||i==t.rY||i==t.rZ||i==t.rAll)return!0}else if(t.scaleEnabled&&(i==t.sX||i==t.sY||i==t.sZ||i==t.sXZ||i==t.sZY||i==t.sYX||i==t.sAll))return!0;return!1},null,this.mainCamera);if(i.hit){if(i.pickedMesh!=this.prevOverMesh){if(this.pointerIsOver=!0,this.clearPrevOverMesh(),this.prevOverMesh=i.pickedMesh,this.rotEnabled)this.savedCol=this.prevOverMesh.getChildren()[0].color,this.prevOverMesh.getChildren()[0].color=e.White();else{var s=this.prevOverMesh.getChildren();s.length>0?(this.savedMat=s[0].material,s[0].material=this.whiteMat):(this.savedMat=this.prevOverMesh.material,this.prevOverMesh.material=this.whiteMat)}"X"==this.prevOverMesh.name?this.xaxis.color=e.White():"Y"==this.prevOverMesh.name?this.yaxis.color=e.White():"Z"==this.prevOverMesh.name&&(this.zaxis.color=e.White())}}else this.pointerIsOver=!1,null!=this.prevOverMesh&&(this.restoreColor(this.prevOverMesh),this.prevOverMesh=null)},t.prototype.clearPrevOverMesh=function(){null!=this.prevOverMesh&&(this.prevOverMesh.visibility=0,this.restoreColor(this.prevOverMesh))},t.prototype.restoreColor=function(t){switch(t.name){case"X":this.xaxis.color=e.Red();break;case"Y":this.yaxis.color=e.Green();break;case"Z":this.zaxis.color=e.Blue()}if(this.rotEnabled)t.getChildren()[0].color=this.savedCol;else{var i=t.getChildren();i.length>0?i[0].material=this.savedMat:t.material=this.savedMat}},t.prototype.onPointerUp=function(t){this.pDown=!1,this.editing&&(this.mainCamera.attachControl(this.canvas),this.setEditing(!1),this.hideBaxis(),null!=this.prevOverMesh&&(this.restoreColor(this.prevOverMesh),this.prevOverMesh=null),this.actHist.add(this.actionType))},t.prototype.setActionType=function(){this.transEnabled?this.actionType=i.TRANS:this.rotEnabled?this.actionType=i.ROT:this.scaleEnabled&&(this.actionType=i.SCALE)},t.prototype.callActionListener=function(t){null!=this.actionListener&&this.actionListener(t)},t.prototype.callActionStartListener=function(t){null!=this.actionStartListener&&this.actionStartListener(t)},t.prototype.callActionEndListener=function(t){null!=this.actionEndListener&&this.actionEndListener(t)},t.prototype.onPointerMove=function(t){if(!this.pDown)return void this.onPointerOver();if(this.editing&&null!=this.prevPos){var i=this.getPosOnPickPlane();if(null!=i){if(this.rotEnabled)this.doRotation(this.mesh,this.axisPicked,i,this.prevPos);else{var s=i.subtract(this.prevPos);if(0==s.x&&0==s.y&&0==s.z)return;this.transEnabled?this.doTranslation(s):this.scaleEnabled&&this.local&&this.doScaling(s)}this.prevPos=i,this.callActionListener(this.actionType)}}},t.prototype.getPickPlane=function(t){var i=t.name;if(this.transEnabled||this.scaleEnabled){if("XZ"==i)return this.pXZ;if("ZY"==i)return this.pZY;if("YX"==i)return this.pYX;if("ALL"==i)return this.pALL;this.ecRoot.getWorldMatrix().invertToRef(this.ecMatrix),p.TransformCoordinatesToRef(this.mainCamera.position,this.ecMatrix,this.ecTOcamera);var s=this.ecTOcamera;if("X"===i)return Math.abs(s.y)>Math.abs(s.z)?this.pXZ:this.pYX;if("Z"===i)return Math.abs(s.y)>Math.abs(s.x)?this.pXZ:this.pZY;if("Y"===i)return Math.abs(s.z)>Math.abs(s.x)?this.pYX:this.pZY}else{if(!this.rotEnabled)return null;this.rotate2=!1,this.ecRoot.getWorldMatrix().invertToRef(this.ecMatrix),p.TransformCoordinatesToRef(this.mainCamera.position,this.ecMatrix,this.ecTOcamera);var s=this.ecTOcamera;switch(i){case"X":return Math.abs(s.x)<.2?(this.rotate2=!0,this.pALL):this.pZY;case"Y":return Math.abs(s.y)<.2?(this.rotate2=!0,this.pALL):this.pXZ;case"Z":return Math.abs(s.z)<.2?(this.rotate2=!0,this.pALL):this.pYX;default:return this.pALL}}},t.prototype.doTranslation=function(t){this.transBy.x=0,this.transBy.y=0,this.transBy.z=0;var i=this.axisPicked.name;"X"!=i&&"XZ"!=i&&"YX"!=i&&"ALL"!=i||(this.local?this.transBy.x=p.Dot(t,this.localX)/(this.localX.length()*this.mesh.scaling.x):this.transBy.x=t.x),"Y"!=i&&"ZY"!=i&&"YX"!=i&&"ALL"!=i||(this.local?this.transBy.y=p.Dot(t,this.localY)/(this.localY.length()*this.mesh.scaling.y):this.transBy.y=t.y),"Z"!=i&&"XZ"!=i&&"ZY"!=i&&"ALL"!=i||(this.local?this.transBy.z=p.Dot(t,this.localZ)/(this.localZ.length()*this.mesh.scaling.z):this.transBy.z=t.z),this.transWithSnap(this.mesh,this.transBy,this.local),this.transBoundsMin&&(this.mesh.position.x=Math.max(this.mesh.position.x,this.transBoundsMin.x),this.mesh.position.y=Math.max(this.mesh.position.y,this.transBoundsMin.y),this.mesh.position.z=Math.max(this.mesh.position.z,this.transBoundsMin.z)),this.transBoundsMax&&(this.mesh.position.x=Math.min(this.mesh.position.x,this.transBoundsMax.x),this.mesh.position.y=Math.min(this.mesh.position.y,this.transBoundsMax.y),this.mesh.position.z=Math.min(this.mesh.position.z,this.transBoundsMax.z)),this.mesh.computeWorldMatrix(!0)},t.prototype.transWithSnap=function(t,i,e){if(this.snapT){var n=!1;if(this.snapTV.addInPlace(i),Math.abs(this.snapTV.x)>this.tSnap.x/t.scaling.x&&(this.snapTV.x>0?i.x=this.tSnap.x:i.x=-this.tSnap.x,i.x=i.x/t.scaling.x,n=!0),Math.abs(this.snapTV.y)>this.tSnap.y/t.scaling.y&&(this.snapTV.y>0?i.y=this.tSnap.y:i.y=-this.tSnap.y,i.y=i.y/t.scaling.y,n=!0),Math.abs(this.snapTV.z)>this.tSnap.z/t.scaling.z&&(this.snapTV.z>0?i.z=this.tSnap.z:i.z=-this.tSnap.z,i.z=i.z/t.scaling.z,n=!0),!n)return;Math.abs(i.x)!==this.tSnap.x/t.scaling.x&&(i.x=0),Math.abs(i.y)!==this.tSnap.y/t.scaling.y&&(i.y=0),Math.abs(i.z)!==this.tSnap.z/t.scaling.z&&(i.z=0),p.FromFloatsToRef(0,0,0,this.snapTV),n=!1}e?(this.mesh.translate(s.X,i.x,l.LOCAL),this.mesh.translate(s.Y,i.y,l.LOCAL),this.mesh.translate(s.Z,i.z,l.LOCAL)):this.mesh.position.addInPlace(i)},t.prototype.doScaling=function(t){this.scale.x=0,this.scale.y=0,this.scale.z=0;var i=this.axisPicked.name;"X"!=i&&"XZ"!=i&&"YX"!=i||(this.scale.x=p.Dot(t,this.localX)/this.localX.length()),"Y"!=i&&"ZY"!=i&&"YX"!=i||(this.scale.y=p.Dot(t,this.localY)/this.localY.length()),"Z"!=i&&"XZ"!=i&&"ZY"!=i||(this.scale.z=p.Dot(t,this.localZ)/this.localZ.length());var s=this.boundingDimesion;if(this.scale.x=this.scale.x/s.x,this.scale.y=this.scale.y/s.y,this.scale.z=this.scale.z/s.z,"ALL"==i){var e=p.Dot(t,this.mainCamera.upVector);e/=Math.max(s.x,s.y,s.z),this.scale.copyFromFloats(e,e,e)}else"XZ"==i?Math.abs(this.scale.x)>Math.abs(this.scale.z)?this.scale.z=this.scale.x:this.scale.x=this.scale.z:"ZY"==i?Math.abs(this.scale.z)>Math.abs(this.scale.y)?this.scale.y=this.scale.z:this.scale.z=this.scale.y:"YX"==i&&(Math.abs(this.scale.y)>Math.abs(this.scale.x)?this.scale.x=this.scale.y:this.scale.y=this.scale.x);this.scaleWithSnap(this.mesh,this.scale),this.scaleBoundsMin&&(this.mesh.scaling.x=Math.max(this.mesh.scaling.x,this.scaleBoundsMin.x),this.mesh.scaling.y=Math.max(this.mesh.scaling.y,this.scaleBoundsMin.y),this.mesh.scaling.z=Math.max(this.mesh.scaling.z,this.scaleBoundsMin.z)),this.scaleBoundsMax&&(this.mesh.scaling.x=Math.min(this.mesh.scaling.x,this.scaleBoundsMax.x),this.mesh.scaling.y=Math.min(this.mesh.scaling.y,this.scaleBoundsMax.y),this.mesh.scaling.z=Math.min(this.mesh.scaling.z,this.scaleBoundsMax.z))},t.prototype.scaleWithSnap=function(t,i){if(this.snapS){var s=!1;if(this.snapSV.addInPlace(i),Math.abs(this.snapSV.x)>this.scaleSnap&&(i.x>0?i.x=this.scaleSnap:i.x=-this.scaleSnap,s=!0),Math.abs(this.snapSV.y)>this.scaleSnap&&(i.y>0?i.y=this.scaleSnap:i.y=-this.scaleSnap,s=!0),Math.abs(this.snapSV.z)>this.scaleSnap&&(i.z>0?i.z=this.scaleSnap:i.z=-this.scaleSnap,s=!0),!s)return;Math.abs(i.x)!==this.scaleSnap&&0!==i.x&&(i.x=0),Math.abs(i.y)!==this.scaleSnap&&0!==i.y&&(i.y=0),Math.abs(i.z)!==this.scaleSnap&&0!==i.z&&(i.z=0),p.FromFloatsToRef(0,0,0,this.snapSV),s=!1}t.scaling.addInPlace(i)},t.prototype.getBoundingDimension=function(t){var i=t.getBoundingInfo().boundingBox,s=i.maximum.subtract(i.minimum);return 0==s.x&&(s.x=1),0==s.y&&(s.y=1),0==s.z&&(s.z=1),s},t.prototype.refreshBoundingInfo=function(){this.boundingDimesion=this.getBoundingDimension(this.mesh)},t.prototype.doRotation=function(t,i,e,n){var h,a=0;i==this.rX?h=this.local?this.localX:s.X:i==this.rY?h=this.local?this.localY:s.Y:i==this.rZ&&(h=this.local?this.localZ:s.Z),this.ecRoot.position.subtractToRef(this.mainCamera.position,this.cameraTOec),a=this.rotate2?this.getAngle2(n,e,this.mainCamera.position,this.cameraTOec,h):this.getAngle(n,e,t.getAbsolutePivotPoint(),this.cameraTOec),this.cameraTOec.normalize(),i==this.rX?(this.snapR&&(this.snapRX+=a,a=0,Math.abs(this.snapRX)>=this.rotSnap&&(a=this.snapRX>0?this.rotSnap:-this.rotSnap,this.snapRX=0)),0!==a&&(p.Dot(h,this.cameraTOec)>=0&&(a*=-1),t.rotate(h,a,l.WORLD))):i==this.rY?(this.snapR&&(this.snapRY+=a,a=0,Math.abs(this.snapRY)>=this.rotSnap&&(a=this.snapRY>0?this.rotSnap:-this.rotSnap,this.snapRY=0)),0!==a&&0!==a&&(p.Dot(h,this.cameraTOec)>=0&&(a*=-1),t.rotate(h,a,l.WORLD))):i==this.rZ?(this.snapR&&(this.snapRZ+=a,a=0,Math.abs(this.snapRZ)>=this.rotSnap&&(a=this.snapRZ>0?this.rotSnap:-this.rotSnap,this.snapRZ=0)),0!==a&&0!==a&&(p.Dot(h,this.cameraTOec)>=0&&(a*=-1),t.rotate(h,a,l.WORLD))):i==this.rAll&&(this.snapR&&(this.snapRA+=a,a=0,Math.abs(this.snapRA)>=this.rotSnap&&(a=this.snapRA>0?this.rotSnap:-this.rotSnap,this.snapRA=0)),0!==a&&t.rotate(this.cameraTOec,-a,l.WORLD)),this.setLocalAxes(this.mesh),this.eulerian&&0!=a&&(t.rotation=t.rotationQuaternion.toEulerAngles(),t.rotationQuaternion=null)},t.prototype.doRotation_old=function(t,i,e,n){var h=this.cN,a=0;p.FromFloatArrayToRef(this.mainCamera.getWorldMatrix().asArray(),8,h),a=this.rotate2?this.getAngle2(n,e,t.getAbsolutePivotPoint(),h,this.localX):this.getAngle(n,e,t.getAbsolutePivotPoint(),h),i==this.rX?(this.snapR&&(this.snapRX+=a,a=0,Math.abs(this.snapRX)>=this.rotSnap&&(a=this.snapRX>0?this.rotSnap:-this.rotSnap,this.snapRX=0)),0!==a&&(this.local?(p.Dot(this.localX,h)<0&&(a*=-1),t.rotate(s.X,a,l.LOCAL)):(this.rotAxis.x=h.x,this.rotAxis.y=0,this.rotAxis.z=0,t.rotate(this.rotAxis,a,l.WORLD)))):i==this.rY?(this.snapR&&(this.snapRY+=a,a=0,Math.abs(this.snapRY)>=this.rotSnap&&(a=this.snapRY>0?this.rotSnap:-this.rotSnap,this.snapRY=0)),0!==a&&(this.local?(p.Dot(this.localY,h)<0&&(a*=-1),t.rotate(s.Y,a,l.LOCAL)):(this.rotAxis.x=0,this.rotAxis.y=h.y,this.rotAxis.z=0,t.rotate(this.rotAxis,a,l.WORLD)))):i==this.rZ?(this.snapR&&(this.snapRZ+=a,a=0,Math.abs(this.snapRZ)>=this.rotSnap&&(a=this.snapRZ>0?this.rotSnap:-this.rotSnap,this.snapRZ=0)),0!==a&&(this.local?(p.Dot(this.localZ,h)<0&&(a*=-1),t.rotate(s.Z,a,l.LOCAL)):(this.rotAxis.x=0,this.rotAxis.y=0,this.rotAxis.z=h.z,t.rotate(this.rotAxis,a,l.WORLD)))):i==this.rAll&&(this.snapR&&(this.snapRA+=a,a=0,Math.abs(this.snapRA)>=this.rotSnap&&(a=this.snapRA>0?this.rotSnap:-this.rotSnap,this.snapRA=0)),0!==a&&(this.scene.useRightHandedSystem&&(a=-a),t.rotate(t.position.subtract(this.mainCamera.position),a,l.WORLD))),this.setLocalAxes(this.mesh),this.eulerian&&0!=a&&(t.rotation=t.rotationQuaternion.toEulerAngles(),t.rotationQuaternion=null)},t.prototype.getPosOnPickPlane=function(){var t=this,i=this.scene.pick(this.scene.pointerX,this.scene.pointerY,function(i){return i==t.pickedPlane},null,this.mainCamera);return i.hit?i.pickedPoint:null},t.prototype.hideBaxis=function(){this.bXaxis.visibility=0,this.bYaxis.visibility=0,this.bZaxis.visibility=0},t.prototype.setAxesVisiblity=function(t){this.transEnabled&&(this.tEndX.visibility=t,this.tEndY.visibility=t,this.tEndZ.visibility=t,this.tEndXZ.visibility=t,this.tEndZY.visibility=t,this.tEndYX.visibility=t,this.tEndAll.visibility=t),this.rotEnabled&&(this.rEndX.visibility=t,this.rEndY.visibility=t,this.rEndZ.visibility=t,this.rEndAll.visibility=t),this.scaleEnabled&&(this.sEndX.visibility=t,this.sEndY.visibility=t,this.sEndZ.visibility=t,this.sEndXZ.visibility=t,this.sEndZY.visibility=t,this.sEndYX.visibility=t,this.sEndAll.visibility=t)},t.prototype.getRotationQuaternion=function(){return this.ecRoot.rotationQuaternion},t.prototype.getPosition=function(){return this.ecRoot.position},t.prototype.isTranslationEnabled=function(){return this.transEnabled},t.prototype.enableTranslation=function(){null==this.tX&&(this.createTransAxes(),this.tCtl.parent=this.ecRoot),this.clearPrevOverMesh(),this.transEnabled||(this.tEndX.visibility=this.visibility,this.tEndY.visibility=this.visibility,this.tEndZ.visibility=this.visibility,this.tEndXZ.visibility=this.visibility,this.tEndZY.visibility=this.visibility,this.tEndYX.visibility=this.visibility,this.tEndAll.visibility=this.visibility,this.transEnabled=!0,this.disableRotation(),this.disableScaling())},t.prototype.disableTranslation=function(){this.transEnabled&&(this.tEndX.visibility=0,this.tEndY.visibility=0,this.tEndZ.visibility=0,this.tEndXZ.visibility=0,this.tEndZY.visibility=0,this.tEndYX.visibility=0,this.tEndAll.visibility=0,this.transEnabled=!1)},t.prototype.isRotationEnabled=function(){return this.rotEnabled},t.prototype.returnEuler=function(t){this.eulerian=t},t.prototype.enableRotation=function(){null==this.rCtl&&(this.createRotAxes(),this.rCtl.parent=this.ecRoot),this.clearPrevOverMesh(),this.rotEnabled||(this.rEndX.visibility=this.visibility,this.rEndY.visibility=this.visibility,this.rEndZ.visibility=this.visibility,this.rEndAll.visibility=this.visibility,this.rEndAll2.visibility=this.visibility,this.rotEnabled=!0,this.disableTranslation(),this.disableScaling())},t.prototype.disableRotation=function(){this.rotEnabled&&(this.rEndX.visibility=0,this.rEndY.visibility=0,this.rEndZ.visibility=0,this.rEndAll.visibility=0,this.rEndAll2.visibility=0,this.rotEnabled=!1)},t.prototype.isScalingEnabled=function(){return this.scaleEnabled},t.prototype.enableScaling=function(){null==this.sX&&(this.createScaleAxes(),this.sCtl.parent=this.ecRoot),this.clearPrevOverMesh(),this.scaleEnabled||(this.sEndX.visibility=this.visibility,this.sEndY.visibility=this.visibility,this.sEndZ.visibility=this.visibility,this.sEndXZ.visibility=this.visibility,this.sEndZY.visibility=this.visibility,this.sEndYX.visibility=this.visibility,this.sEndAll.visibility=this.visibility,this.scaleEnabled=!0,this.disableTranslation(),this.disableRotation())},t.prototype.disableScaling=function(){this.scaleEnabled&&(this.sEndX.visibility=0,this.sEndY.visibility=0,this.sEndZ.visibility=0,this.sEndXZ.visibility=0,this.sEndZY.visibility=0,this.sEndYX.visibility=0,this.sEndAll.visibility=0,this.scaleEnabled=!1)},t.prototype.setScaleBounds=function(t,i){this.scaleBoundsMin=t||null,this.scaleBoundsMax=i||null,null!=this.scaleBoundsMin&&(0==this.scaleBoundsMin.x&&(this.scaleBoundsMin.x=1e-8),0==this.scaleBoundsMin.y&&(this.scaleBoundsMin.y=1e-8),0==this.scaleBoundsMin.z&&(this.scaleBoundsMin.z=1e-8))},t.prototype.removeScaleBounds=function(){this.scaleBoundsMin=null,this.scaleBoundsMax=null},t.prototype.setTransBounds=function(t,i){this.transBoundsMin=t||null,this.transBoundsMax=i||null},t.prototype.removeTransBounds=function(){this.transBoundsMin=null,this.transBoundsMax=null},t.prototype.setRotBounds=function(t,i){this.rotBoundsMin=t||null,this.rotBoundsMax=i||null},t.prototype.removeRotBounds=function(){this.rotBoundsMin=null,this.rotBoundsMax=null},t.prototype.createCommonAxes=function(){var t=new h("guideCtl",this.scene);this.bXaxis=h.CreateLines("bxAxis",[new p(-100,0,0),new p(100,0,0)],this.scene),this.bYaxis=h.CreateLines("byAxis",[new p(0,-100,0),new p(0,100,0)],this.scene),this.bZaxis=h.CreateLines("bzAxis",[new p(0,0,-100),new p(0,0,100)],this.scene),this.bXaxis.isPickable=!1,this.bYaxis.isPickable=!1,this.bZaxis.isPickable=!1,this.bXaxis.parent=t,this.bYaxis.parent=t,this.bZaxis.parent=t,this.bXaxis.color=e.Red(),this.bYaxis.color=e.Green(),this.bZaxis.color=e.Blue(),this.hideBaxis();var i=this.axesLen*this.axesScale*.75;return this.xaxis=h.CreateLines("xAxis",[new p(0,0,0),new p(i,0,0)],this.scene),this.yaxis=h.CreateLines("yAxis",[new p(0,0,0),new p(0,i,0)],this.scene),this.zaxis=h.CreateLines("zAxis",[new p(0,0,0),new p(0,0,i)],this.scene),this.xaxis.isPickable=!1,this.yaxis.isPickable=!1,this.zaxis.isPickable=!1,this.xaxis.parent=t,this.yaxis.parent=t,this.zaxis.parent=t,this.xaxis.color=e.Red(),this.yaxis.color=e.Green(),this.zaxis.color=e.Blue(),this.xaxis.renderingGroupId=1,this.yaxis.renderingGroupId=1,this.zaxis.renderingGroupId=1,t},t.prototype.createPickPlanes=function(){this.pALL=h.CreatePlane("pALL",5,this.scene),this.pXZ=h.CreatePlane("pXZ",5,this.scene),this.pZY=h.CreatePlane("pZY",5,this.scene),this.pYX=h.CreatePlane("pYX",5,this.scene),this.pALL.isPickable=!1,this.pXZ.isPickable=!1,this.pZY.isPickable=!1,this.pYX.isPickable=!1,this.pALL.visibility=0,this.pXZ.visibility=0,this.pZY.visibility=0,this.pYX.visibility=0,this.pALL.renderingGroupId=1,this.pXZ.renderingGroupId=1,this.pZY.renderingGroupId=1,this.pYX.renderingGroupId=1,this.pALL.lookAt(this.mainCamera.position),this.pXZ.rotate(s.X,1.57),this.pZY.rotate(s.Y,1.57);var t=new h("pickPlanes",this.scene);return this.pALL.parent=t,this.pXZ.parent=t,this.pZY.parent=t,this.pYX.parent=t,t},t.prototype.createTransAxes=function(){var t=2*this.pickWidth*this.axesScale,i=this.axesLen*this.axesScale;this.tCtl=new h("tarnsCtl",this.scene),this.tX=this.extrudeBox(t/2,i),this.tX.name="X",this.tY=this.tX.clone("Y"),this.tZ=this.tX.clone("Z"),this.tXZ=a.CreatePlane("XZ",{size:2*t},this.scene),this.tZY=this.tXZ.clone("ZY"),this.tYX=this.tXZ.clone("YX"),this.tXZ.rotation.x=1.57,this.tZY.rotation.y=-1.57,this.tXZ.position.x=t,this.tXZ.position.z=t,this.tZY.position.z=t,this.tZY.position.y=t,this.tYX.position.y=t,this.tYX.position.x=t,this.tAll=h.CreateBox("ALL",2*t,this.scene),this.tX.parent=this.tCtl,this.tY.parent=this.tCtl,this.tZ.parent=this.tCtl,this.tXZ.parent=this.tCtl,this.tZY.parent=this.tCtl,this.tYX.parent=this.tCtl,this.tAll.parent=this.tCtl,this.tX.rotation.y=1.57,this.tY.rotation.x-=1.57,this.tX.visibility=0,this.tY.visibility=0,this.tZ.visibility=0,this.tXZ.visibility=0,this.tZY.visibility=0,this.tYX.visibility=0,this.tAll.visibility=0,this.tX.isPickable=!1,this.tY.isPickable=!1,this.tZ.isPickable=!1,this.tXZ.isPickable=!1,this.tZY.isPickable=!1,this.tYX.isPickable=!1,this.tAll.isPickable=!1;var s=i/5,e=t;this.tEndX=h.CreateCylinder("tEndX",s,0,e,6,1,this.scene),this.tEndY=this.tEndX.clone("tEndY"),this.tEndZ=this.tEndX.clone("tEndZ"),this.tEndXZ=this.createTriangle("XZ",1.75*e,this.scene),this.tEndZY=this.tEndXZ.clone("ZY"),this.tEndYX=this.tEndXZ.clone("YX"),this.tEndAll=a.CreatePolyhedron("tEndAll",{type:1,size:e/2},this.scene),this.tEndX.rotation.x=1.57,this.tEndY.rotation.x=1.57,this.tEndZ.rotation.x=1.57,this.tEndXZ.rotation.x=-1.57,this.tEndZY.rotation.x=-1.57,this.tEndYX.rotation.x=-1.57,this.tEndX.parent=this.tX,this.tEndY.parent=this.tY,this.tEndZ.parent=this.tZ,this.tEndXZ.parent=this.tXZ,this.tEndZY.parent=this.tZY,this.tEndYX.parent=this.tYX,this.tEndAll.parent=this.tAll,this.tEndX.position.z=i-s/2,this.tEndY.position.z=i-s/2,this.tEndZ.position.z=i-s/2,this.tEndX.material=this.redMat,this.tEndY.material=this.greenMat,this.tEndZ.material=this.blueMat,this.tEndXZ.material=this.greenMat,this.tEndZY.material=this.redMat,this.tEndYX.material=this.blueMat,this.tEndAll.material=this.yellowMat,this.tEndX.renderingGroupId=2,this.tEndY.renderingGroupId=2,this.tEndZ.renderingGroupId=2,this.tEndXZ.renderingGroupId=2,this.tEndZY.renderingGroupId=2,this.tEndYX.renderingGroupId=2,this.tEndAll.renderingGroupId=2,this.tEndX.isPickable=!1,this.tEndY.isPickable=!1,this.tEndZ.isPickable=!1,this.tEndXZ.isPickable=!1,this.tEndZY.isPickable=!1,this.tEndYX.isPickable=!1,this.tEndAll.isPickable=!1},t.prototype.createTriangle=function(t,i,s){var e=new r(i/2,-i/2).addLineTo(i/2,i/2).addLineTo(-i/2,i/2).addLineTo(i/2,-i/2);return new BABYLON.PolygonMeshBuilder(t,e,s).build()},t.prototype.setRotGuideFull=function(t){this.guideSize=t?360:180,null!=this.rCtl&&(this.rCtl.dispose(),this.rAll.dispose(),this.rCtl=null,this.enableRotation())},t.prototype.createRotAxes=function(){var t=this.axesLen*this.axesScale*2;this.rCtl=new h("rotCtl",this.scene),this.rX=this.createTube(t/2,this.guideSize),this.rX.name="X",this.rY=this.createTube(t/2,this.guideSize),this.rY.name="Y",this.rZ=this.createTube(t/2,this.guideSize),this.rZ.name="Z",this.rAll=this.createTube(t/1.75,360),this.rAll.name="ALL",this.rX.rotation.z=1.57,this.rZ.rotation.x=-1.57,this.rX.bakeCurrentTransformIntoVertices(),this.rZ.bakeCurrentTransformIntoVertices(),this.rAll.rotation.x=1.57,this.rX.parent=this.rCtl,this.rY.parent=this.rCtl,this.rZ.parent=this.rCtl,this.rAll.parent=this.pALL,this.rX.visibility=0,this.rY.visibility=0,this.rZ.visibility=0,this.rAll.visibility=0,this.rX.isPickable=!1,this.rY.isPickable=!1,this.rZ.isPickable=!1,this.rAll.isPickable=!1;var i=t;this.rEndX=this.createCircle(i/2,this.guideSize,!1),this.rEndY=this.rEndX.clone(""),this.rEndZ=this.rEndX.clone(""),this.rEndAll=this.createCircle(i/1.75,360,!1),this.rEndAll2=this.createCircle(i/2,360,!1),this.rEndX.parent=this.rX,this.rEndY.parent=this.rY,this.rEndZ.parent=this.rZ,this.rEndX.rotation.z=1.57,this.rEndZ.rotation.x=-1.57,this.rEndAll.parent=this.rAll,this.rEndAll2.parent=this.rAll,this.rEndX.color=e.Red(),this.rEndY.color=e.Green(),this.rEndZ.color=e.Blue(),this.rEndAll.color=e.Yellow(),this.rEndAll2.color=e.Gray(),this.rEndX.renderingGroupId=2,this.rEndY.renderingGroupId=2,this.rEndZ.renderingGroupId=2,this.rEndAll.renderingGroupId=2,this.rEndAll2.renderingGroupId=2,this.rEndX.isPickable=!1,this.rEndY.isPickable=!1,this.rEndZ.isPickable=!1,this.rEndAll.isPickable=!1},t.prototype.extrudeBox=function(t,i){var s=[new p(t,t,0),new p(-t,t,0),new p(-t,-t,0),new p(t,-t,0),new p(t,t,0)],e=[new p(0,0,0),new p(0,0,i)];return h.ExtrudeShape("",s,e,1,0,2,this.scene)},t.prototype.createCircle=function(t,i,s){null===i&&(i=360);for(var e,n,a=[],r=3.14/180,o=0,l=0;l<=i;l+=5)e=t*Math.cos(l*r),n=90==l?t:270==l?-t:t*Math.sin(l*r),a[o]=new p(e,0,n),o++;if(s){t-=.04;for(var l=0;l<=i;l+=5)e=t*Math.cos(l*r),n=90==l?t:270==l?-t:t*Math.sin(l*r),a[o]=new p(e,0,n),o++}return h.CreateLines("",a,this.scene)},t.prototype.createTube=function(t,i){null===i&&(i=360);for(var s,e,n=[],a=3.14/180,r=0,o=0;o<=i;o+=30)s=t*Math.cos(o*a),e=90==o?t:270==o?-t:t*Math.sin(o*a),n[r]=new p(s,0,e),r++;return h.CreateTube("",n,this.pickWidth*this.axesScale*2,3,null,BABYLON.Mesh.NO_CAP,this.scene)},t.prototype.createScaleAxes=function(){var t=2*this.pickWidth*this.axesScale,i=this.axesLen*this.axesScale;this.sCtl=new h("sCtl",this.scene),this.sX=this.extrudeBox(t/2,i),this.sX.name="X",this.sY=this.sX.clone("Y"),this.sZ=this.sX.clone("Z"),this.sXZ=a.CreatePlane("XZ",{size:2*t},this.scene),this.sZY=this.sXZ.clone("ZY"),this.sYX=this.sXZ.clone("YX"),this.sXZ.rotation.x=1.57,this.sZY.rotation.y=-1.57,this.sXZ.position.x=t,this.sXZ.position.z=t,this.sZY.position.z=t,this.sZY.position.y=t,this.sYX.position.y=t,this.sYX.position.x=t,this.sAll=h.CreateBox("ALL",2*t,this.scene),this.sX.parent=this.sCtl,this.sY.parent=this.sCtl,this.sZ.parent=this.sCtl,this.sAll.parent=this.sCtl,this.sXZ.parent=this.sCtl,this.sZY.parent=this.sCtl,this.sYX.parent=this.sCtl,this.sX.rotation.y=1.57,this.sY.rotation.x-=1.57,this.sX.visibility=0,this.sY.visibility=0,this.sZ.visibility=0,this.sXZ.visibility=0,this.sZY.visibility=0,this.sYX.visibility=0,this.sAll.visibility=0,this.sX.isPickable=!1,this.sY.isPickable=!1,this.sZ.isPickable=!1,this.sXZ.isPickable=!1,this.sZY.isPickable=!1,this.sYX.isPickable=!1,this.sAll.isPickable=!1;var s=t;this.sEndX=h.CreateBox("",s,this.scene),this.sEndY=this.sEndX.clone(""),this.sEndZ=this.sEndX.clone(""),this.sEndXZ=this.createTriangle("XZ",1.75*s,this.scene),this.sEndZY=this.sEndXZ.clone("ZY"),this.sEndYX=this.sEndXZ.clone("YX"),this.sEndAll=a.CreatePolyhedron("sEndAll",{type:1,size:s/2},this.scene),this.sEndXZ.rotation.x=-1.57,this.sEndZY.rotation.x=-1.57,this.sEndYX.rotation.x=-1.57, 2 | this.sEndX.parent=this.sX,this.sEndY.parent=this.sY,this.sEndZ.parent=this.sZ,this.sEndXZ.parent=this.sXZ,this.sEndZY.parent=this.sZY,this.sEndYX.parent=this.sYX,this.sEndAll.parent=this.sAll,this.sEndX.position.z=i-s/2,this.sEndY.position.z=i-s/2,this.sEndZ.position.z=i-s/2,this.sEndX.material=this.redMat,this.sEndY.material=this.greenMat,this.sEndZ.material=this.blueMat,this.sEndXZ.material=this.greenMat,this.sEndZY.material=this.redMat,this.sEndYX.material=this.blueMat,this.sEndAll.material=this.yellowMat,this.sEndX.renderingGroupId=2,this.sEndY.renderingGroupId=2,this.sEndZ.renderingGroupId=2,this.sEndXZ.renderingGroupId=2,this.sEndZY.renderingGroupId=2,this.sEndYX.renderingGroupId=2,this.sEndAll.renderingGroupId=2,this.sEndX.isPickable=!1,this.sEndY.isPickable=!1,this.sEndZ.isPickable=!1,this.sEndXZ.isPickable=!1,this.sEndZY.isPickable=!1,this.sEndYX.isPickable=!1,this.sEndAll.isPickable=!1},t.prototype.setLocalAxes=function(t){var i=t.getWorldMatrix();p.FromFloatArrayToRef(i.asArray(),0,this.localX),p.FromFloatArrayToRef(i.asArray(),4,this.localY),p.FromFloatArrayToRef(i.asArray(),8,this.localZ)},t.prototype.setVisibility=function(t){this.visibility=t},t.prototype.setLocal=function(t){this.local!=t&&(this.local=t,t||(this.ecRoot.rotationQuaternion=o.Identity()))},t.prototype.isLocal=function(){return this.local},t.prototype.setTransSnap=function(t){this.snapT=t},t.prototype.setRotSnap=function(t){this.snapR=t},t.prototype.setScaleSnap=function(t){this.snapS=t},t.prototype.setTransSnapValue=function(t){this.tSnap.copyFromFloats(t,t,t),this.transSnap=t},t.prototype.setRotSnapValue=function(t){this.rotSnap=t},t.prototype.setScaleSnapValue=function(t){this.scaleSnap=t},t.prototype.getAngle2=function(t,i,s,e,n){var h=p.Dot(e,n);n.scaleToRef(h,this.tv1),s.addToRef(this.tv1,this.tv2);var a=this.tv2;this.mainCamera.getWorldMatrix().invertToRef(this.tm),p.TransformCoordinatesToRef(this.tv2,this.tm,this.tv2);var r=0;a.x>=0&&a.y>=0?r=1:a.x<=0&&a.y>=0?r=2:a.x<=0&&a.y<=0?r=3:a.x>=0&&a.y<=0&&(r=4),p.TransformCoordinatesToRef(t,this.tm,this.tv1),p.TransformCoordinatesToRef(i,this.tm,this.tv2),this.tv2.subtractInPlace(this.tv1);var o=this.tv2,l=o.length(),c="";o.x>=0&&o.y>=0?c=o.x>=o.y?"r":"u":o.x<=0&&o.y>=0?c=-o.x>=o.y?"l":"u":o.x<=0&&o.y<=0?c=-o.x>=-o.y?"l":"d":o.x>=0&&o.y<=0&&(c=o.x>=-o.y?"r":"d");var d=0;return"d"==c?d=1==r||4==r?1:-1:"u"==c?d=1==r||4==r?-1:1:"r"==c?d=2==r||1==r?1:-1:"l"==c&&(d=2==r||1==r?-1:1),d*l},t.prototype.getAngle=function(t,i,s,e){t.subtractToRef(s,this.tv1),i.subtractToRef(s,this.tv2),p.CrossToRef(this.tv1,this.tv2,this.tv3);var n=Math.asin(this.tv3.length()/(this.tv1.length()*this.tv2.length()));return p.Dot(this.tv3,e)>0&&(n*=-1),n},t.prototype.createMaterials=function(i){this.redMat=t.getStandardMaterial("redMat",e.Red(),i),this.greenMat=t.getStandardMaterial("greenMat",e.Green(),i),this.blueMat=t.getStandardMaterial("blueMat",e.Blue(),i),this.whiteMat=t.getStandardMaterial("whiteMat",e.White(),i),this.yellowMat=t.getStandardMaterial("whiteMat",e.Yellow(),i)},t.prototype.disposeMaterials=function(){this.redMat.dispose(),this.greenMat.dispose(),this.blueMat.dispose(),this.whiteMat.dispose(),this.yellowMat.dispose()},t.getStandardMaterial=function(t,i,s){var n=new c(t,s);return n.emissiveColor=i,n.diffuseColor=e.Black(),n.specularColor=e.Black(),n.backFaceCulling=!1,n},t}();t.EditControl=d;var u=function(){function t(t,i){this.lastMax=10,this.acts=new Array,this.last=-1,this.current=-1,this.mesh=t,this.lastMax=i-1,this.add()}return t.prototype.setCapacity=function(t){if(0==t)return void console.error("capacity should be more than zero");this.lastMax=t-1,this.last=-1,this.current=-1,this.acts=new Array,this.add()},t.prototype.add=function(t){void 0===t&&(t=null);var i=new y(this.mesh,t);this.current0){var t=this.acts[this.current].getActionType();return this.current--,this.acts[this.current].perform(this.mesh),t}},t.prototype.redo=function(){if(this.current", 13 | "license": "Apache-2.0", 14 | "contributors": [], 15 | "main": "dist/MeshEditor.min.js", 16 | "types": "dist/MeshEditor.d.ts", 17 | "dependencies": {}, 18 | "devDependencies": { 19 | "babylonjs": "^3.0.0", 20 | "babylonjs-editcontrol": "^2.5.1", 21 | "uglify-js": "^2.8.22" 22 | }, 23 | "scripts": { 24 | "compile": "tsc -p src", 25 | "min": "uglifyjs dist/MeshEditor.js -o dist/MeshEditor.min.js -mc", 26 | "build": "npm run compile && npm run min" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/EditControl.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | declare namespace org.ssatguru.babylonjs.component { 3 | import AbstractMesh = BABYLON.AbstractMesh; 4 | import Camera = BABYLON.Camera; 5 | import Mesh = BABYLON.Mesh; 6 | import Quaternion = BABYLON.Quaternion; 7 | import Vector3 = BABYLON.Vector3; 8 | class EditControl { 9 | private mesh; 10 | private canvas; 11 | private scene; 12 | private mainCamera; 13 | private ecRoot; 14 | private local; 15 | private snapT; 16 | private snapR; 17 | private transSnap; 18 | private rotSnap; 19 | private axesLen; 20 | private axesScale; 21 | private redMat; 22 | private greenMat; 23 | private blueMat; 24 | private whiteMat; 25 | private yellowMat; 26 | private actHist; 27 | private renderer; 28 | private pointerdown; 29 | private pointerup; 30 | private pointermove; 31 | private visibility; 32 | constructor(mesh: Mesh, camera: Camera, canvas: HTMLCanvasElement, scale: number, eulerian?: boolean); 33 | private checkQuaternion(); 34 | private distFromCamera; 35 | private cameraTOec; 36 | private cameraNormal; 37 | private setAxesScale(); 38 | private setAxesRotation(); 39 | private ecMatrix; 40 | private ecTOcamera; 41 | private rotRotGuides(); 42 | private renderLoopProcess(); 43 | switchTo(mesh: Mesh, eulerian?: boolean): void; 44 | setUndoCount(c: number): void; 45 | undo(): void; 46 | redo(): void; 47 | detach(): void; 48 | private prevState; 49 | private hidden; 50 | hide(): void; 51 | private hideCommonAxes(); 52 | private showCommonAxes(); 53 | show(): void; 54 | isHidden(): boolean; 55 | private disposeAll(); 56 | private actionListener; 57 | private actionStartListener; 58 | private actionEndListener; 59 | addActionListener(actionListener: (actionType: number) => void): void; 60 | removeActionListener(): void; 61 | addActionStartListener(actionStartListener: (actionType: number) => void): void; 62 | removeActionStartListener(): void; 63 | addActionEndListener(actionEndListener: (actionType: number) => void): void; 64 | removeActionEndListener(): void; 65 | removeAllActionListeners(): void; 66 | private pDown; 67 | private axisPicked; 68 | private onPointerDown(evt); 69 | private setEditing(editing); 70 | isEditing(): boolean; 71 | private detachControl(cam, can); 72 | private prevOverMesh; 73 | private pointerIsOver; 74 | isPointerOver(): boolean; 75 | private savedMat; 76 | private savedCol; 77 | private onPointerOver(); 78 | private clearPrevOverMesh(); 79 | private restoreColor(mesh); 80 | private editing; 81 | private onPointerUp(evt); 82 | private actionType; 83 | private setActionType(); 84 | private callActionListener(at); 85 | private callActionStartListener(at); 86 | private callActionEndListener(at); 87 | private prevPos; 88 | private snapRX; 89 | private snapRY; 90 | private snapRZ; 91 | private onPointerMove(evt); 92 | private snapTV; 93 | private transBy; 94 | private getPickPlane(axis); 95 | private doTranslation(diff); 96 | private transWithSnap(mesh, trans, local); 97 | private snapS; 98 | private snapSX; 99 | private snapSY; 100 | private snapSZ; 101 | private snapSA; 102 | private snapSV; 103 | private scaleSnap; 104 | private scale; 105 | private doScaling(diff); 106 | private scaleWithSnap(mesh, p); 107 | private boundingDimesion; 108 | private getBoundingDimension(mesh); 109 | refreshBoundingInfo(): void; 110 | private eulerian; 111 | private snapRA; 112 | private cN; 113 | private rotAxis; 114 | private doRotation(mesh, axis, newPos, prevPos); 115 | private getPosOnPickPlane(); 116 | private hideBaxis(); 117 | private setAxesVisiblity(v); 118 | getRotationQuaternion(): Quaternion; 119 | getPosition(): Vector3; 120 | private transEnabled; 121 | isTranslationEnabled(): boolean; 122 | enableTranslation(): void; 123 | disableTranslation(): void; 124 | private rotEnabled; 125 | isRotationEnabled(): boolean; 126 | returnEuler(euler: boolean): void; 127 | enableRotation(): void; 128 | disableRotation(): void; 129 | private scaleEnabled; 130 | isScalingEnabled(): boolean; 131 | enableScaling(): void; 132 | disableScaling(): void; 133 | private scaleBoundsMin; 134 | private scaleBoundsMax; 135 | setScaleBounds(min?: Vector3, max?: Vector3): void; 136 | removeScaleBounds(): void; 137 | private transBoundsMin; 138 | private transBoundsMax; 139 | setTransBounds(min?: Vector3, max?: Vector3): void; 140 | removeTransBounds(): void; 141 | private rotBoundsMin; 142 | private rotBoundsMax; 143 | setRotBounds(min?: Vector3, max?: Vector3): void; 144 | removeRotBounds(): void; 145 | private bXaxis; 146 | private bYaxis; 147 | private bZaxis; 148 | private xaxis; 149 | private yaxis; 150 | private zaxis; 151 | private createCommonAxes(); 152 | private pickedPlane; 153 | private pALL; 154 | private pXZ; 155 | private pZY; 156 | private pYX; 157 | private createPickPlanes(); 158 | private tCtl; 159 | private tX; 160 | private tY; 161 | private tZ; 162 | private tXZ; 163 | private tZY; 164 | private tYX; 165 | private tAll; 166 | private tEndX; 167 | private tEndY; 168 | private tEndZ; 169 | private tEndXZ; 170 | private tEndZY; 171 | private tEndYX; 172 | private tEndAll; 173 | private createTransAxes(); 174 | private createTriangle(name, w, scene); 175 | private rCtl; 176 | private rX; 177 | private rY; 178 | private rZ; 179 | private rAll; 180 | private rEndX; 181 | private rEndY; 182 | private rEndZ; 183 | private rEndAll; 184 | private rEndAll2; 185 | private guideSize; 186 | setRotGuideFull(y: boolean): void; 187 | private createRotAxes(); 188 | private extrudeBox(w, l); 189 | private createCircle(r, t, double); 190 | private createTube(r, t?); 191 | private sCtl; 192 | private sX; 193 | private sY; 194 | private sZ; 195 | private sXZ; 196 | private sZY; 197 | private sYX; 198 | private sAll; 199 | private sEndX; 200 | private sEndY; 201 | private sEndZ; 202 | private sEndXZ; 203 | private sEndZY; 204 | private sEndYX; 205 | private sEndAll; 206 | private createScaleAxes(); 207 | private localX; 208 | private localY; 209 | private localZ; 210 | private setLocalAxes(mesh); 211 | setVisibility(v: number): void; 212 | setLocal(l: boolean): void; 213 | isLocal(): boolean; 214 | setTransSnap(s: boolean): void; 215 | setRotSnap(s: boolean): void; 216 | setScaleSnap(s: boolean): void; 217 | private tSnap; 218 | setTransSnapValue(t: number): void; 219 | setRotSnapValue(r: number): void; 220 | setScaleSnapValue(r: number): void; 221 | private static getAngle(p1, p2, p, cN); 222 | private createMaterials(scene); 223 | private disposeMaterials(); 224 | private static getStandardMaterial(name, col, scene); 225 | } 226 | class ActHist { 227 | private mesh; 228 | private lastMax; 229 | private acts; 230 | private last; 231 | private current; 232 | constructor(mesh: AbstractMesh, capacity: number); 233 | setCapacity(c: number): void; 234 | add(at?: number): void; 235 | undo(): number; 236 | redo(): number; 237 | } 238 | class Act { 239 | private p; 240 | private rQ; 241 | private rE; 242 | private s; 243 | private at; 244 | constructor(mesh: AbstractMesh, at: number); 245 | getActionType(): number; 246 | perform(mesh: AbstractMesh): void; 247 | } 248 | } 249 | -------------------------------------------------------------------------------- /src/MeshEditor.ts: -------------------------------------------------------------------------------- 1 | 2 | namespace org.ssatguru.babylonjs.component { 3 | 4 | import ArcRotateCamera=BABYLON.ArcRotateCamera; 5 | import MeshBuilder=BABYLON.MeshBuilder; 6 | import Color3=BABYLON.Color3; 7 | import Camera=BABYLON.Camera; 8 | import IndicesArray=BABYLON.IndicesArray; 9 | import Vector3=BABYLON.Vector3; 10 | import LinesMesh=BABYLON.LinesMesh; 11 | import Matrix=BABYLON.Matrix; 12 | import Mesh=BABYLON.Mesh; 13 | import Scene=BABYLON.Scene; 14 | import StandardMaterial=BABYLON.StandardMaterial; 15 | import Ray=BABYLON.Ray; 16 | import Path2=BABYLON.Path2; 17 | import PickingInfo=BABYLON.PickingInfo; 18 | import VertexBuffer=BABYLON.VertexBuffer; 19 | import EditControl=org.ssatguru.babylonjs.component.EditControl; 20 | 21 | export class MeshEditor { 22 | 23 | camera: Camera; 24 | canvas:HTMLCanvasElement; 25 | scene:Scene; 26 | 27 | vertices: number[]|Float32Array; 28 | faceVertices: IndicesArray; 29 | mesh: Mesh; 30 | facePicked: number=0; 31 | ec: EditControl=null; 32 | 33 | mode: String="F"; 34 | 35 | faceSelector: Mesh; 36 | edgeSelector: Mesh; 37 | pointSelector: Mesh; 38 | 39 | selectedMesh: Mesh; 40 | 41 | public enablePoint() { 42 | if (this.mode=="P") return; 43 | this.mode="P"; 44 | this.faceSelector.visibility=0; 45 | this.edgeSelector.visibility=0; 46 | this.ec.hide(); 47 | } 48 | public enableEdge() { 49 | if (this.mode=="E") return; 50 | this.mode="E"; 51 | this.faceSelector.visibility=0; 52 | this.pointSelector.visibility=0; 53 | this.ec.hide(); 54 | 55 | } 56 | public enableFace() { 57 | if (this.mode=="F") return; 58 | this.mode="F"; 59 | this.edgeSelector.visibility=0; 60 | this.pointSelector.visibility=0; 61 | this.ec.hide(); 62 | } 63 | 64 | constructor(mesh: Mesh,camera: Camera,canvas: HTMLCanvasElement,scene: Scene) { 65 | this.mesh=mesh; 66 | this.camera=camera; 67 | this.canvas=canvas; 68 | this.scene=scene; 69 | 70 | this.mesh.markVerticesDataAsUpdatable(VertexBuffer.PositionKind,true); 71 | 72 | this.vertices=mesh.getVerticesData(VertexBuffer.PositionKind); 73 | this.faceVertices=mesh.getIndices(); 74 | 75 | // let vrtColors = box.getVerticesData(VertexBuffer.ColorKind); 76 | // console.log(vrtColors); 77 | //box.setVerticesData(VertexBuffer.ColorKind,vrtColors,true,3); 78 | // this.vrtColors=new Array(this.vertices.length*4/3); 79 | // this.clearColors(this.vrtColors); 80 | 81 | this.faceSelector=this.createFaceSelector(scene); 82 | this.edgeSelector=this.createEdgeSelector(scene); 83 | this.pointSelector=new Mesh("pointSelector",scene); 84 | this.ec=null; 85 | 86 | scene.pointerDownPredicate=(mesh)=>{ 87 | if (mesh==this.mesh) return true; 88 | else return false; 89 | } 90 | scene.onPointerDown=(evt,pickResult) => { 91 | 92 | //select only on right click 93 | if(!(evt.button==2)) return; 94 | if(pickResult.hit) { 95 | if(pickResult.pickedMesh!=this.mesh) return; 96 | this.facePicked=pickResult.faceId; 97 | 98 | // let f: number=pickResult.faceId; 99 | // 100 | // //pick even-odd faces 101 | // let next: number=f+1; 102 | // if(Math.floor(f/2) { 135 | if(this.mode=="F") { 136 | this.updateFacePosition(this.facePicked,this.faceSelector); 137 | } else if(this.mode=="E") { 138 | this.updateEdgePosition(this.facePicked,this.edgeSelector); 139 | } else if(this.mode=="P") { 140 | this.updatePointPosition(this.facePicked,this.pointSelector); 141 | } 142 | this.mesh.updateVerticesData(VertexBuffer.PositionKind,this.vertices,false,false); 143 | }) 144 | return ec; 145 | } 146 | 147 | private createFaceSelector_old(scene: Scene): Mesh { 148 | let fs: Mesh=this.createTriangle("selector",1,scene); 149 | fs.material=new StandardMaterial("impactMat",scene); 150 | (fs.material).diffuseColor=Color3.Gray(); 151 | fs.visibility=0.8; 152 | fs.markVerticesDataAsUpdatable(VertexBuffer.PositionKind,true); 153 | fs.renderingGroupId=1; 154 | return fs; 155 | } 156 | private createFaceSelector(scene: Scene): Mesh { 157 | let fs: LinesMesh=Mesh.CreateLines("edgeSelector",[new Vector3(-1,0,0),new Vector3(1,0,0),new Vector3(0,0,1),new Vector3(-1,0,0)],scene); 158 | fs.color=Color3.Black(); 159 | fs.visibility=0; 160 | fs.markVerticesDataAsUpdatable(VertexBuffer.PositionKind,true); 161 | fs.renderingGroupId=1; 162 | return fs; 163 | } 164 | private createEdgeSelector(scene: Scene): Mesh { 165 | let es: LinesMesh=Mesh.CreateLines("edgeSelector",[new Vector3(-1,0,0),new Vector3(1,0,0)],scene); 166 | es.color=Color3.Black(); 167 | es.isPickable=false; 168 | es.renderingGroupId=1; 169 | es.visibility=0; 170 | es.markVerticesDataAsUpdatable(VertexBuffer.PositionKind,true); 171 | return es; 172 | } 173 | 174 | v1v: Vector3=new Vector3(0,0,0); 175 | v2v: Vector3=new Vector3(0,0,0); 176 | v3v: Vector3=new Vector3(0,0,0); 177 | 178 | private highLightFace(faceId: number,faceSelector: Mesh) { 179 | this.getFaceVertices(faceId,this.mesh,this.faceVertices); 180 | 181 | //set selector rotation so it is parallel to the triangular face selected 182 | let a1: Vector3=this.v1v.subtract(this.v2v); 183 | let a2: Vector3=this.v3v.subtract(this.v2v); 184 | faceSelector.rotation=this.getRotation(a1,a2); 185 | 186 | //baycenter position 187 | faceSelector.position.x=(this.v1v.x+this.v2v.x+this.v3v.x)/3; 188 | faceSelector.position.y=(this.v1v.y+this.v2v.y+this.v3v.y)/3; 189 | faceSelector.position.z=(this.v1v.z+this.v2v.z+this.v3v.z)/3; 190 | 191 | let verts: number[]|Float32Array=faceSelector.getVerticesData(VertexBuffer.PositionKind); 192 | let sm_i: Matrix=faceSelector.getWorldMatrix().clone().invert(); 193 | 194 | Vector3.TransformCoordinatesToRef(this.v1v,sm_i,this.pTemp); 195 | verts[0]=this.pTemp.x; 196 | verts[1]=this.pTemp.y; 197 | verts[2]=this.pTemp.z; 198 | 199 | Vector3.TransformCoordinatesToRef(this.v2v,sm_i,this.pTemp); 200 | verts[3]=this.pTemp.x; 201 | verts[4]=this.pTemp.y; 202 | verts[5]=this.pTemp.z; 203 | 204 | Vector3.TransformCoordinatesToRef(this.v3v,sm_i,this.pTemp); 205 | verts[6]=this.pTemp.x; 206 | verts[7]=this.pTemp.y; 207 | verts[8]=this.pTemp.z; 208 | 209 | //if using line mesh 210 | verts[9]=verts[0]; 211 | verts[10]=verts[1]; 212 | verts[11]=verts[2]; 213 | 214 | faceSelector.setVerticesData(VertexBuffer.PositionKind,verts,true); 215 | //this.ec.switchTo(faceSelector,true); 216 | 217 | //face vertices color 218 | // let cc1=v1*4; 219 | // let cc2=v2*4; 220 | // let cc3=v3*4; 221 | // this.setColor(cc1,this.vrtColors,color); 222 | // this.setColor(cc2,this.vrtColors,color); 223 | // this.setColor(cc3,this.vrtColors,color); 224 | // this.mesh.setVerticesData(VertexBuffer.ColorKind,this.vrtColors,true); 225 | } 226 | 227 | pTemp: Vector3=Vector3.Zero(); 228 | private updateFacePosition(faceId: number,faceSelector: Mesh) { 229 | let i: number=faceId*3; 230 | 231 | //index into the vertices array 232 | let v1=this.faceVertices[i]; 233 | let v2=this.faceVertices[i+1]; 234 | let v3=this.faceVertices[i+2]; 235 | 236 | //start of the three vertices 237 | let v=this.vertices; 238 | let v1s=v1*3; 239 | let v2s=v2*3; 240 | let v3s=v3*3; 241 | 242 | let verts: number[]|Float32Array=faceSelector.getVerticesData(VertexBuffer.PositionKind); 243 | let sm: Matrix=faceSelector.getWorldMatrix(); 244 | 245 | let mm_i: Matrix=this.mesh.getWorldMatrix().clone().invert(); 246 | 247 | //lets get the selector vertex in world space 248 | Vector3.TransformCoordinatesFromFloatsToRef(verts[0],verts[1],verts[2],sm,this.pTemp); 249 | //now lets get the selector vertex in mesh's local space. 250 | Vector3.TransformCoordinatesFromFloatsToRef(this.pTemp.x,this.pTemp.y,this.pTemp.z,mm_i,this.pTemp); 251 | 252 | v[v1s]=this.pTemp.x; 253 | v[v1s+1]=this.pTemp.y; 254 | v[v1s+2]=this.pTemp.z; 255 | 256 | Vector3.TransformCoordinatesFromFloatsToRef(verts[3],verts[4],verts[5],sm,this.pTemp); 257 | Vector3.TransformCoordinatesFromFloatsToRef(this.pTemp.x,this.pTemp.y,this.pTemp.z,mm_i,this.pTemp); 258 | 259 | v[v2s]=this.pTemp.x; 260 | v[v2s+1]=this.pTemp.y; 261 | v[v2s+2]=this.pTemp.z; 262 | 263 | Vector3.TransformCoordinatesFromFloatsToRef(verts[6],verts[7],verts[8],sm,this.pTemp); 264 | Vector3.TransformCoordinatesFromFloatsToRef(this.pTemp.x,this.pTemp.y,this.pTemp.z,mm_i,this.pTemp); 265 | 266 | v[v3s]=this.pTemp.x; 267 | v[v3s+1]=this.pTemp.y; 268 | v[v3s+2]=this.pTemp.z; 269 | }; 270 | 271 | 272 | 273 | private highLightEdge(faceId: number,pickPoint: Vector3,edgeSelector: Mesh) { 274 | this.getFaceVertices(faceId,this.mesh,this.faceVertices); 275 | //ev1 and ev2 are the two vertices of the edge 276 | let ev1: Vector3; 277 | let ev2: Vector3; 278 | //ev3 will be used to get rotation 279 | let ev3: Vector3; 280 | 281 | let h1=this.getDistance(pickPoint,this.v1v,this.v2v); 282 | let h2=this.getDistance(pickPoint,this.v2v,this.v3v); 283 | let h3=this.getDistance(pickPoint,this.v3v,this.v1v); 284 | 285 | let min_h=Math.min(h1,h2,h3); 286 | 287 | if(min_h==h1) {ev1=this.v1v; ev2=this.v2v; ev3=this.v3v; this.ep1=1; this.ep2=2;} 288 | if(min_h==h2) {ev1=this.v2v; ev2=this.v3v; ev3=this.v1v; this.ep1=2; this.ep2=3;} 289 | if(min_h==h3) {ev1=this.v3v; ev2=this.v1v; ev3=this.v2v; this.ep1=3; this.ep2=1;} 290 | 291 | 292 | //set selector rotation so it is parallel to the triangular face selected 293 | let a1: Vector3=ev1.subtract(ev2); 294 | let a2: Vector3=ev3.subtract(ev2); 295 | edgeSelector.rotation=this.getRotation(a1,a2); 296 | 297 | //baycenter position 298 | edgeSelector.position.x=(ev1.x+ev2.x)/2; 299 | edgeSelector.position.y=(ev1.y+ev2.y)/2; 300 | edgeSelector.position.z=(ev1.z+ev2.z)/2; 301 | 302 | let verts: number[]|Float32Array=edgeSelector.getVerticesData(VertexBuffer.PositionKind); 303 | let sm_i: Matrix=edgeSelector.getWorldMatrix().clone().invert(); 304 | 305 | Vector3.TransformCoordinatesToRef(ev1,sm_i,this.pTemp); 306 | verts[0]=this.pTemp.x; 307 | verts[1]=this.pTemp.y; 308 | verts[2]=this.pTemp.z; 309 | 310 | Vector3.TransformCoordinatesToRef(ev2,sm_i,this.pTemp); 311 | verts[3]=this.pTemp.x; 312 | verts[4]=this.pTemp.y; 313 | verts[5]=this.pTemp.z; 314 | 315 | edgeSelector.setVerticesData(VertexBuffer.PositionKind,verts,true); 316 | this.ec.switchTo(edgeSelector,true); 317 | } 318 | 319 | private ep1: number; 320 | private ep2: number; 321 | private updateEdgePosition(faceId: number,edgeSelector: Mesh) { 322 | let i: number=faceId*3; 323 | 324 | //index into the vertices array 325 | let v1=this.faceVertices[i+this.ep1-1]; 326 | let v2=this.faceVertices[i+this.ep2-1]; 327 | 328 | //start of the three vertices 329 | let v=this.vertices; 330 | let v1s=v1*3; 331 | let v2s=v2*3; 332 | 333 | 334 | let verts: number[]|Float32Array=edgeSelector.getVerticesData(VertexBuffer.PositionKind); 335 | let sm: Matrix=edgeSelector.getWorldMatrix(); 336 | 337 | let mm_i: Matrix=this.mesh.getWorldMatrix().clone().invert(); 338 | 339 | //lets get the selector vertex in world space 340 | Vector3.TransformCoordinatesFromFloatsToRef(verts[0],verts[1],verts[2],sm,this.pTemp); 341 | //now lets get the selector vertex in mesh's local space. 342 | Vector3.TransformCoordinatesFromFloatsToRef(this.pTemp.x,this.pTemp.y,this.pTemp.z,mm_i,this.pTemp); 343 | 344 | v[v1s]=this.pTemp.x; 345 | v[v1s+1]=this.pTemp.y; 346 | v[v1s+2]=this.pTemp.z; 347 | 348 | Vector3.TransformCoordinatesFromFloatsToRef(verts[3],verts[4],verts[5],sm,this.pTemp); 349 | Vector3.TransformCoordinatesFromFloatsToRef(this.pTemp.x,this.pTemp.y,this.pTemp.z,mm_i,this.pTemp); 350 | 351 | v[v2s]=this.pTemp.x; 352 | v[v2s+1]=this.pTemp.y; 353 | v[v2s+2]=this.pTemp.z; 354 | }; 355 | 356 | private p; 357 | private highLightPoint(faceId: number,pickPoint: Vector3,pointSelector: Mesh) { 358 | 359 | this.getFaceVertices(faceId,this.mesh,this.faceVertices); 360 | //p1 is the vertex of the point 361 | let p1: Vector3; 362 | //p2 and p3 will be used for edit control orientation 363 | let p2: Vector3; 364 | let p3: Vector3; 365 | 366 | 367 | //get the vertex the pickpoint is closest to 368 | let l1=pickPoint.subtract(this.v1v).length(); 369 | let l2=pickPoint.subtract(this.v2v).length(); 370 | let l3=pickPoint.subtract(this.v3v).length(); 371 | 372 | let min_l=Math.min(l1,l2,l3); 373 | if(min_l==l1) {this.p=1; p1=this.v1v; p2=this.v3v; p3=this.v2v;} 374 | if(min_l==l2) {this.p=2; p1=this.v2v; p2=this.v1v; p3=this.v3v;} 375 | if(min_l==l3) {this.p=3; p1=this.v3v; p2=this.v2v; p3=this.v1v;} 376 | 377 | //set selector rotation so that it's Y axis(up) is parallel to the selected face normal 378 | let a1: Vector3=p2.subtract(p1); 379 | let a2: Vector3=p3.subtract(p1); 380 | pointSelector.rotation=this.getRotation(a1,a2); 381 | 382 | pointSelector.position=p1; 383 | 384 | this.ec.switchTo(pointSelector,true); 385 | } 386 | 387 | private updatePointPosition(faceId: number,pointSelector: Mesh) { 388 | let i: number=faceId*3; 389 | 390 | //index into the vertices array 391 | let v1=this.faceVertices[i+this.p-1]; 392 | 393 | //start of the three vertices 394 | let v=this.vertices; 395 | let v1s=v1*3; 396 | 397 | //now lets get the selector vertex in mesh's local space. 398 | let mm_i: Matrix=this.mesh.getWorldMatrix().clone().invert(); 399 | Vector3.TransformCoordinatesToRef(pointSelector.position,mm_i,this.pTemp); 400 | 401 | v[v1s]=this.pTemp.x; 402 | v[v1s+1]=this.pTemp.y; 403 | v[v1s+2]=this.pTemp.z; 404 | 405 | }; 406 | 407 | private getFaceVertices(faceId: number,mesh: Mesh,faceVertices: IndicesArray) { 408 | let i: number=faceId*3; 409 | 410 | //index into the vertices array 411 | let v1=faceVertices[i]; 412 | let v2=faceVertices[i+1]; 413 | let v3=faceVertices[i+2]; 414 | 415 | let mm: Matrix=mesh.getWorldMatrix(); 416 | 417 | //start of the three vertices 418 | let v=this.vertices; 419 | let v1s=v1*3; 420 | let v2s=v2*3; 421 | let v3s=v3*3; 422 | 423 | //get vertices in world frame of reference 424 | Vector3.TransformCoordinatesFromFloatsToRef(v[v1s],v[v1s+1],v[v1s+2],mm,this.v1v); 425 | Vector3.TransformCoordinatesFromFloatsToRef(v[v2s],v[v2s+1],v[v2s+2],mm,this.v2v); 426 | Vector3.TransformCoordinatesFromFloatsToRef(v[v3s],v[v3s+1],v[v3s+2],mm,this.v3v); 427 | 428 | } 429 | 430 | private setMaterial(mesh: Mesh,color: Color3,scene: Scene) { 431 | mesh.material=new StandardMaterial("",scene); 432 | (mesh.material).diffuseColor=color; 433 | } 434 | 435 | //reset each face to white 436 | private clearColors(vrtColors) { 437 | let j=vrtColors.length-3; 438 | for(let i=0;ithis.camera).target=this.ec.getPosition(); 485 | } 486 | 487 | private createTriangle(name: string,w: number,scene: Scene) { 488 | let p: Path2=new Path2(w/2,-w/2).addLineTo(w/2,w/2).addLineTo(-w/2,w/2).addLineTo(w/2,-w/2); 489 | var s=new BABYLON.PolygonMeshBuilder(name,p,scene) 490 | var t=s.build(true); 491 | return t; 492 | } 493 | 494 | 495 | private getRotation(a1: Vector3,a2: Vector3): Vector3 { 496 | //get three orthogonal axis a1,v,a3 497 | //where v is perpendicular to a1 and a2 498 | //and a3 is perpendicular to a1 and v 499 | Vector3.CrossToRef(a1,a2,this.pTemp); 500 | let a3: Vector3=Vector3.Cross(this.pTemp,a1); 501 | //get the rotation of the frame of referencec made uo by a1,v,a3 502 | return Vector3.RotationFromAxis(a3,this.pTemp,a1); 503 | } 504 | /** 505 | * returns distance of point p1 from line segment formed by points p2 and p3 506 | */ 507 | private getDistance(p1: Vector3,p2: Vector3,p3: Vector3): number { 508 | let v1: Vector3=p1.subtract(p2); 509 | let v2: Vector3=p3.subtract(p2); 510 | //angle between v1 & v2 511 | let angle: number=Math.acos((Vector3.Dot(v1,v2.normalize())/v1.length())); 512 | return v1.length()*Math.sin(angle); 513 | 514 | 515 | } 516 | 517 | } 518 | } 519 | -------------------------------------------------------------------------------- /src/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "declaration":true, 4 | "target": "ES5", 5 | "module": "system", 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "emitDecoratorMetadata": true, 9 | "experimentalDecorators": true, 10 | "removeComments": true, 11 | "noImplicitAny": false, 12 | "outDir":"../dist" 13 | }, 14 | "include": ["../node_modules/**/*.d.ts","../src/**/*.ts"] 15 | } 16 | 17 | --------------------------------------------------------------------------------