chili3d 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/main.yml +26 -0
- package/.vscode/c_cpp_properties.json +30 -0
- package/.vscode/launch.json +21 -0
- package/.vscode/settings.json +8 -0
- package/Dockerfile +7 -0
- package/LICENSE +661 -0
- package/README.md +184 -0
- package/biome.json +67 -0
- package/compose.yml +7 -0
- package/cpp/CMakeLists.txt +96 -0
- package/cpp/CMakePresets.json +43 -0
- package/cpp/README.md +21 -0
- package/cpp/src/converter.cpp +413 -0
- package/cpp/src/factory.cpp +612 -0
- package/cpp/src/geometry.cpp +204 -0
- package/cpp/src/mesher.cpp +330 -0
- package/cpp/src/opencascade.cpp +414 -0
- package/cpp/src/shape.cpp +447 -0
- package/cpp/src/shared.cpp +83 -0
- package/cpp/src/shared.hpp +211 -0
- package/cpp/src/transient.cpp +29 -0
- package/cpp/src/utils.cpp +114 -0
- package/cpp/src/utils.hpp +25 -0
- package/cpp/test/index.html +146 -0
- package/package.json +49 -0
- package/packages/chili/package.json +11 -0
- package/packages/chili/src/application.ts +200 -0
- package/packages/chili/src/bodys/arc.ts +61 -0
- package/packages/chili/src/bodys/boolean.ts +32 -0
- package/packages/chili/src/bodys/box.ts +73 -0
- package/packages/chili/src/bodys/circle.ts +57 -0
- package/packages/chili/src/bodys/cone.ts +64 -0
- package/packages/chili/src/bodys/cylinder.ts +69 -0
- package/packages/chili/src/bodys/ellipse.ts +85 -0
- package/packages/chili/src/bodys/face.ts +72 -0
- package/packages/chili/src/bodys/fuse.ts +44 -0
- package/packages/chili/src/bodys/index.ts +16 -0
- package/packages/chili/src/bodys/line.ts +48 -0
- package/packages/chili/src/bodys/polygon.ts +40 -0
- package/packages/chili/src/bodys/prism.ts +49 -0
- package/packages/chili/src/bodys/pyramid.ts +64 -0
- package/packages/chili/src/bodys/rect.ts +69 -0
- package/packages/chili/src/bodys/revolve.ts +54 -0
- package/packages/chili/src/bodys/sphere.ts +48 -0
- package/packages/chili/src/bodys/sweep.ts +67 -0
- package/packages/chili/src/bodys/wire.ts +36 -0
- package/packages/chili/src/commands/application/index.ts +10 -0
- package/packages/chili/src/commands/application/newDocument.ts +17 -0
- package/packages/chili/src/commands/application/openDocument.ts +35 -0
- package/packages/chili/src/commands/application/performanceTest.ts +64 -0
- package/packages/chili/src/commands/application/saveDocument.ts +24 -0
- package/packages/chili/src/commands/application/toFile.ts +35 -0
- package/packages/chili/src/commands/application/toggleDynamicWorkplane.ts +15 -0
- package/packages/chili/src/commands/application/wechatGroup.ts +42 -0
- package/packages/chili/src/commands/boolean.ts +109 -0
- package/packages/chili/src/commands/create/arc.ts +110 -0
- package/packages/chili/src/commands/create/bezier.ts +116 -0
- package/packages/chili/src/commands/create/box.ts +59 -0
- package/packages/chili/src/commands/create/circle.ts +54 -0
- package/packages/chili/src/commands/create/cone.ts +104 -0
- package/packages/chili/src/commands/create/converter.ts +159 -0
- package/packages/chili/src/commands/create/copySubShape.ts +37 -0
- package/packages/chili/src/commands/create/curveProjection.ts +61 -0
- package/packages/chili/src/commands/create/cylinder.ts +96 -0
- package/packages/chili/src/commands/create/ellipse.ts +95 -0
- package/packages/chili/src/commands/create/group.ts +205 -0
- package/packages/chili/src/commands/create/index.ts +26 -0
- package/packages/chili/src/commands/create/line.ts +61 -0
- package/packages/chili/src/commands/create/loft.ts +149 -0
- package/packages/chili/src/commands/create/offset.ts +131 -0
- package/packages/chili/src/commands/create/polygon.ts +104 -0
- package/packages/chili/src/commands/create/prism.ts +52 -0
- package/packages/chili/src/commands/create/pyramid.ts +56 -0
- package/packages/chili/src/commands/create/rect.ts +105 -0
- package/packages/chili/src/commands/create/revolve.ts +62 -0
- package/packages/chili/src/commands/create/section.ts +31 -0
- package/packages/chili/src/commands/create/sphere.ts +48 -0
- package/packages/chili/src/commands/create/sweep.ts +39 -0
- package/packages/chili/src/commands/create/thickSolid.ts +50 -0
- package/packages/chili/src/commands/createActCommand.ts +26 -0
- package/packages/chili/src/commands/createCommand.ts +41 -0
- package/packages/chili/src/commands/delete.ts +38 -0
- package/packages/chili/src/commands/folder.ts +18 -0
- package/packages/chili/src/commands/importExport.ts +97 -0
- package/packages/chili/src/commands/index.ts +17 -0
- package/packages/chili/src/commands/measure/angle.ts +130 -0
- package/packages/chili/src/commands/measure/index.ts +6 -0
- package/packages/chili/src/commands/measure/length.ts +57 -0
- package/packages/chili/src/commands/measure/select.module.css +68 -0
- package/packages/chili/src/commands/measure/select.ts +228 -0
- package/packages/chili/src/commands/modify/array.ts +447 -0
- package/packages/chili/src/commands/modify/break.ts +78 -0
- package/packages/chili/src/commands/modify/brush.ts +100 -0
- package/packages/chili/src/commands/modify/chamfer.ts +70 -0
- package/packages/chili/src/commands/modify/explode.ts +91 -0
- package/packages/chili/src/commands/modify/fillet.ts +69 -0
- package/packages/chili/src/commands/modify/index.ts +16 -0
- package/packages/chili/src/commands/modify/mirror.ts +49 -0
- package/packages/chili/src/commands/modify/move.ts +39 -0
- package/packages/chili/src/commands/modify/removeFeature.ts +56 -0
- package/packages/chili/src/commands/modify/removeSubShapes.ts +44 -0
- package/packages/chili/src/commands/modify/rotate.ts +112 -0
- package/packages/chili/src/commands/modify/split.ts +81 -0
- package/packages/chili/src/commands/modify/transformedCommand.ts +100 -0
- package/packages/chili/src/commands/modify/trim.ts +254 -0
- package/packages/chili/src/commands/multistepCommand.ts +125 -0
- package/packages/chili/src/commands/redo.ts +16 -0
- package/packages/chili/src/commands/undo.ts +16 -0
- package/packages/chili/src/commands/workingPlane.ts +150 -0
- package/packages/chili/src/comparers/NumberEqualityComparer.ts +12 -0
- package/packages/chili/src/comparers/XYZEqualityComparer.ts +12 -0
- package/packages/chili/src/comparers/index.ts +5 -0
- package/packages/chili/src/document.ts +145 -0
- package/packages/chili/src/editEventHandler.ts +20 -0
- package/packages/chili/src/index.ts +12 -0
- package/packages/chili/src/selection.ts +178 -0
- package/packages/chili/src/services/commandService.ts +105 -0
- package/packages/chili/src/services/editorService.ts +46 -0
- package/packages/chili/src/services/hotkeyService.ts +102 -0
- package/packages/chili/src/services/index.ts +6 -0
- package/packages/chili/src/snap/dimension.ts +33 -0
- package/packages/chili/src/snap/handlers/angleSnapEventHandler.ts +60 -0
- package/packages/chili/src/snap/handlers/index.ts +7 -0
- package/packages/chili/src/snap/handlers/lengthSnapEventHandler.ts +117 -0
- package/packages/chili/src/snap/handlers/pointSnapEventHandler.ts +176 -0
- package/packages/chili/src/snap/handlers/snapEventHandler.ts +288 -0
- package/packages/chili/src/snap/index.ts +6 -0
- package/packages/chili/src/snap/snap.ts +50 -0
- package/packages/chili/src/snap/snaps/axisSnap.ts +57 -0
- package/packages/chili/src/snap/snaps/baseSnap.ts +69 -0
- package/packages/chili/src/snap/snaps/featurePointStrategy.ts +64 -0
- package/packages/chili/src/snap/snaps/index.ts +7 -0
- package/packages/chili/src/snap/snaps/objectSnap.ts +264 -0
- package/packages/chili/src/snap/snaps/planeSnap.ts +55 -0
- package/packages/chili/src/snap/snaps/pointOnCurveSnap.ts +24 -0
- package/packages/chili/src/snap/tracking/axis.ts +32 -0
- package/packages/chili/src/snap/tracking/axisTracking.ts +46 -0
- package/packages/chili/src/snap/tracking/index.ts +6 -0
- package/packages/chili/src/snap/tracking/objectTracking.ts +90 -0
- package/packages/chili/src/snap/tracking/trackingBase.ts +40 -0
- package/packages/chili/src/snap/tracking/trackingSnap.ts +201 -0
- package/packages/chili/src/step/angleStep.ts +32 -0
- package/packages/chili/src/step/index.ts +8 -0
- package/packages/chili/src/step/lengthStep.ts +32 -0
- package/packages/chili/src/step/pointStep.ts +87 -0
- package/packages/chili/src/step/selectStep.ts +130 -0
- package/packages/chili/src/step/step.ts +55 -0
- package/packages/chili/src/utils.ts +19 -0
- package/packages/chili/test/command.test.ts +4 -0
- package/packages/chili-builder/package.json +13 -0
- package/packages/chili-builder/src/additionalModule.ts +15 -0
- package/packages/chili-builder/src/appBuilder.ts +176 -0
- package/packages/chili-builder/src/defaultDataExchange.ts +152 -0
- package/packages/chili-builder/src/index.ts +5 -0
- package/packages/chili-builder/src/ribbon.ts +129 -0
- package/packages/chili-controls/package.json +9 -0
- package/packages/chili-controls/src/collection.ts +96 -0
- package/packages/chili-controls/src/controls.ts +83 -0
- package/packages/chili-controls/src/converters/colorConverter.ts +39 -0
- package/packages/chili-controls/src/converters/index.ts +8 -0
- package/packages/chili-controls/src/converters/numberConverter.ts +15 -0
- package/packages/chili-controls/src/converters/stringConverter.ts +13 -0
- package/packages/chili-controls/src/converters/urlConverter.ts +10 -0
- package/packages/chili-controls/src/converters/xyzConverter.ts +28 -0
- package/packages/chili-controls/src/expander/expander.module.css +38 -0
- package/packages/chili-controls/src/expander/expander.ts +59 -0
- package/packages/chili-controls/src/expander/index.ts +4 -0
- package/packages/chili-controls/src/htmlProps.ts +10 -0
- package/packages/chili-controls/src/index.ts +10 -0
- package/packages/chili-controls/src/radioGroup.module.css +20 -0
- package/packages/chili-controls/src/radioGroup.ts +54 -0
- package/packages/chili-controls/src/utils.ts +20 -0
- package/packages/chili-controls/test/converter.test.ts +70 -0
- package/packages/chili-controls/test/styleMock.js +4 -0
- package/packages/chili-core/package.json +7 -0
- package/packages/chili-core/src/application.ts +38 -0
- package/packages/chili-core/src/command/command.ts +154 -0
- package/packages/chili-core/src/command/commandKeys.ts +8 -0
- package/packages/chili-core/src/command/decarator.ts +43 -0
- package/packages/chili-core/src/command/index.ts +6 -0
- package/packages/chili-core/src/config.ts +145 -0
- package/packages/chili-core/src/constants.ts +8 -0
- package/packages/chili-core/src/dataExchange.ts +12 -0
- package/packages/chili-core/src/document.ts +25 -0
- package/packages/chili-core/src/editor.ts +12 -0
- package/packages/chili-core/src/foundation/asyncController.ts +55 -0
- package/packages/chili-core/src/foundation/binding.ts +132 -0
- package/packages/chili-core/src/foundation/collection.ts +208 -0
- package/packages/chili-core/src/foundation/converter.ts +9 -0
- package/packages/chili-core/src/foundation/deepObserver.ts +154 -0
- package/packages/chili-core/src/foundation/disposable.ts +18 -0
- package/packages/chili-core/src/foundation/dto/index.ts +9 -0
- package/packages/chili-core/src/foundation/equalityComparer.ts +6 -0
- package/packages/chili-core/src/foundation/gc.ts +36 -0
- package/packages/chili-core/src/foundation/history.ts +237 -0
- package/packages/chili-core/src/foundation/id.ts +25 -0
- package/packages/chili-core/src/foundation/index.ts +26 -0
- package/packages/chili-core/src/foundation/lazy.ts +18 -0
- package/packages/chili-core/src/foundation/linkedList.ts +141 -0
- package/packages/chili-core/src/foundation/logger.ts +45 -0
- package/packages/chili-core/src/foundation/messageType.ts +8 -0
- package/packages/chili-core/src/foundation/objectStorage.ts +50 -0
- package/packages/chili-core/src/foundation/observer.ts +147 -0
- package/packages/chili-core/src/foundation/precision.ts +8 -0
- package/packages/chili-core/src/foundation/pubsub.ts +74 -0
- package/packages/chili-core/src/foundation/result.ts +69 -0
- package/packages/chili-core/src/foundation/storage.ts +10 -0
- package/packages/chili-core/src/foundation/transaction.ts +77 -0
- package/packages/chili-core/src/foundation/utils/debounce.ts +15 -0
- package/packages/chili-core/src/foundation/utils/download.ts +16 -0
- package/packages/chili-core/src/foundation/utils/index.ts +6 -0
- package/packages/chili-core/src/foundation/utils/readFileAsync.ts +84 -0
- package/packages/chili-core/src/i18n/i18n.ts +107 -0
- package/packages/chili-core/src/i18n/index.ts +5 -0
- package/packages/chili-core/src/i18n/keys.ts +265 -0
- package/packages/chili-core/src/index.ts +26 -0
- package/packages/chili-core/src/material.ts +269 -0
- package/packages/chili-core/src/math/boundingBox.ts +226 -0
- package/packages/chili-core/src/math/index.ts +14 -0
- package/packages/chili-core/src/math/line.ts +55 -0
- package/packages/chili-core/src/math/lineSegment.ts +166 -0
- package/packages/chili-core/src/math/mathUtils.ts +45 -0
- package/packages/chili-core/src/math/matrix4.ts +414 -0
- package/packages/chili-core/src/math/plane.ts +96 -0
- package/packages/chili-core/src/math/planeAngle.ts +53 -0
- package/packages/chili-core/src/math/quaternion.ts +131 -0
- package/packages/chili-core/src/math/ray.ts +30 -0
- package/packages/chili-core/src/math/xy.ts +104 -0
- package/packages/chili-core/src/math/xyz.ts +181 -0
- package/packages/chili-core/src/model/component.ts +305 -0
- package/packages/chili-core/src/model/facebaseNode.ts +17 -0
- package/packages/chili-core/src/model/folderNode.ts +289 -0
- package/packages/chili-core/src/model/geometryNode.ts +185 -0
- package/packages/chili-core/src/model/groupNode.ts +19 -0
- package/packages/chili-core/src/model/index.ts +12 -0
- package/packages/chili-core/src/model/meshNode.ts +53 -0
- package/packages/chili-core/src/model/node.ts +315 -0
- package/packages/chili-core/src/model/shapeNode.ts +195 -0
- package/packages/chili-core/src/model/visualNode.ts +39 -0
- package/packages/chili-core/src/modelManager.ts +147 -0
- package/packages/chili-core/src/navigation.ts +58 -0
- package/packages/chili-core/src/property.ts +60 -0
- package/packages/chili-core/src/selection.ts +33 -0
- package/packages/chili-core/src/selectionFilter.ts +28 -0
- package/packages/chili-core/src/serialize/index.ts +4 -0
- package/packages/chili-core/src/serialize/serializer.ts +231 -0
- package/packages/chili-core/src/service.ts +10 -0
- package/packages/chili-core/src/shape/curve.ts +174 -0
- package/packages/chili-core/src/shape/geometry.ts +17 -0
- package/packages/chili-core/src/shape/index.ts +12 -0
- package/packages/chili-core/src/shape/lineType.ts +7 -0
- package/packages/chili-core/src/shape/meshData.ts +347 -0
- package/packages/chili-core/src/shape/shape.ts +104 -0
- package/packages/chili-core/src/shape/shapeConverter.ts +17 -0
- package/packages/chili-core/src/shape/shapeFactory.ts +58 -0
- package/packages/chili-core/src/shape/shapeType.ts +75 -0
- package/packages/chili-core/src/shape/surface.ts +154 -0
- package/packages/chili-core/src/snapType.ts +32 -0
- package/packages/chili-core/src/ui/button.ts +16 -0
- package/packages/chili-core/src/ui/combobox.ts +27 -0
- package/packages/chili-core/src/ui/dialog.ts +7 -0
- package/packages/chili-core/src/ui/index.ts +8 -0
- package/packages/chili-core/src/ui/ribbon.ts +15 -0
- package/packages/chili-core/src/ui/window.ts +13 -0
- package/packages/chili-core/src/visual/act.ts +59 -0
- package/packages/chili-core/src/visual/cameraController.ts +22 -0
- package/packages/chili-core/src/visual/cursorType.ts +4 -0
- package/packages/chili-core/src/visual/detectedData.ts +14 -0
- package/packages/chili-core/src/visual/eventHandler.ts +15 -0
- package/packages/chili-core/src/visual/highlighter.ts +16 -0
- package/packages/chili-core/src/visual/index.ts +20 -0
- package/packages/chili-core/src/visual/meshExporter.ts +11 -0
- package/packages/chili-core/src/visual/meshUtils.ts +276 -0
- package/packages/chili-core/src/visual/textGenerator.ts +8 -0
- package/packages/chili-core/src/visual/view.ts +80 -0
- package/packages/chili-core/src/visual/viewGizmo.ts +8 -0
- package/packages/chili-core/src/visual/viewport.ts +10 -0
- package/packages/chili-core/src/visual/visual.ts +24 -0
- package/packages/chili-core/src/visual/visualContext.ts +29 -0
- package/packages/chili-core/src/visual/visualFactory.ts +10 -0
- package/packages/chili-core/src/visual/visualObject.ts +25 -0
- package/packages/chili-core/src/visual/visualShape.ts +30 -0
- package/packages/chili-core/test/binding.test.ts +95 -0
- package/packages/chili-core/test/boundingBox.test.ts +60 -0
- package/packages/chili-core/test/collection.test.ts +53 -0
- package/packages/chili-core/test/history.test.ts +42 -0
- package/packages/chili-core/test/line.test.ts +75 -0
- package/packages/chili-core/test/linesegment.test.ts +98 -0
- package/packages/chili-core/test/linkedList.test.ts +82 -0
- package/packages/chili-core/test/math.test.ts +34 -0
- package/packages/chili-core/test/matrix.test.ts +129 -0
- package/packages/chili-core/test/node.test.ts +122 -0
- package/packages/chili-core/test/nodeList.test.ts +247 -0
- package/packages/chili-core/test/observer.test.ts +91 -0
- package/packages/chili-core/test/plane.test.ts +31 -0
- package/packages/chili-core/test/quaternion.test.ts +14 -0
- package/packages/chili-core/test/result.test.ts +24 -0
- package/packages/chili-core/test/serializer.test.ts +58 -0
- package/packages/chili-core/test/snapType.test.ts +10 -0
- package/packages/chili-core/test/task.test.ts +41 -0
- package/packages/chili-core/test/testDocument.ts +70 -0
- package/packages/chili-core/test/transaction.test.ts +42 -0
- package/packages/chili-core/test/visual.test.ts +42 -0
- package/packages/chili-core/test/xyz.test.ts +260 -0
- package/packages/chili-geo/package.json +9 -0
- package/packages/chili-geo/src/index.ts +4 -0
- package/packages/chili-geo/src/utils.ts +113 -0
- package/packages/chili-i18n/package.json +9 -0
- package/packages/chili-i18n/src/en.ts +270 -0
- package/packages/chili-i18n/src/index.ts +8 -0
- package/packages/chili-i18n/src/pt-br.ts +67 -0
- package/packages/chili-i18n/src/zh-cn.ts +269 -0
- package/packages/chili-storage/package.json +9 -0
- package/packages/chili-storage/src/index.ts +4 -0
- package/packages/chili-storage/src/indexedDBStorage.ts +150 -0
- package/packages/chili-three/package.json +13 -0
- package/packages/chili-three/src/cameraController.ts +335 -0
- package/packages/chili-three/src/common.ts +65 -0
- package/packages/chili-three/src/constants.ts +12 -0
- package/packages/chili-three/src/highlightable.ts +13 -0
- package/packages/chili-three/src/index.ts +4 -0
- package/packages/chili-three/src/meshExporter.ts +69 -0
- package/packages/chili-three/src/outlinePass.js +340 -0
- package/packages/chili-three/src/texture_points.jpg +0 -0
- package/packages/chili-three/src/threeGeometry.ts +207 -0
- package/packages/chili-three/src/threeGeometryFactory.ts +120 -0
- package/packages/chili-three/src/threeHelper.ts +174 -0
- package/packages/chili-three/src/threeHighlighter.ts +257 -0
- package/packages/chili-three/src/threeView.module.css +39 -0
- package/packages/chili-three/src/threeView.ts +669 -0
- package/packages/chili-three/src/threeViewEventHandler.ts +193 -0
- package/packages/chili-three/src/threeVisual.ts +92 -0
- package/packages/chili-three/src/threeVisualContext.ts +435 -0
- package/packages/chili-three/src/threeVisualFactory.ts +12 -0
- package/packages/chili-three/src/threeVisualObject.ts +442 -0
- package/packages/chili-three/src/viewGizmo.ts +305 -0
- package/packages/chili-three/test/cameraControls.ts +10 -0
- package/packages/chili-three/test/testDocument.ts +68 -0
- package/packages/chili-three/test/testEdge.ts +171 -0
- package/packages/chili-three/test/testView.ts +78 -0
- package/packages/chili-three/test/three.test.ts +44 -0
- package/packages/chili-three/test/viewGizmo.ts +12 -0
- package/packages/chili-ui/package.json +12 -0
- package/packages/chili-ui/src/cursor/draw.cur +0 -0
- package/packages/chili-ui/src/cursor/index.ts +17 -0
- package/packages/chili-ui/src/dialog.module.css +63 -0
- package/packages/chili-ui/src/dialog.ts +42 -0
- package/packages/chili-ui/src/editor.module.css +83 -0
- package/packages/chili-ui/src/editor.ts +142 -0
- package/packages/chili-ui/src/home/home.module.css +301 -0
- package/packages/chili-ui/src/home/home.ts +243 -0
- package/packages/chili-ui/src/home/index.ts +4 -0
- package/packages/chili-ui/src/home/languageSelector.ts +27 -0
- package/packages/chili-ui/src/home/navigation3DSelector.ts +27 -0
- package/packages/chili-ui/src/home/themeSelector.ts +34 -0
- package/packages/chili-ui/src/index.ts +5 -0
- package/packages/chili-ui/src/mainWindow.module.css +144 -0
- package/packages/chili-ui/src/mainWindow.ts +154 -0
- package/packages/chili-ui/src/okCancel.module.css +54 -0
- package/packages/chili-ui/src/okCancel.ts +58 -0
- package/packages/chili-ui/src/permanent.module.css +44 -0
- package/packages/chili-ui/src/permanent.ts +31 -0
- package/packages/chili-ui/src/project/index.ts +4 -0
- package/packages/chili-ui/src/project/projectView.module.css +37 -0
- package/packages/chili-ui/src/project/projectView.ts +77 -0
- package/packages/chili-ui/src/project/toolBar.module.css +16 -0
- package/packages/chili-ui/src/project/toolBar.ts +73 -0
- package/packages/chili-ui/src/project/tree/index.ts +5 -0
- package/packages/chili-ui/src/project/tree/tree.module.css +16 -0
- package/packages/chili-ui/src/project/tree/tree.ts +265 -0
- package/packages/chili-ui/src/project/tree/treeItem.module.css +21 -0
- package/packages/chili-ui/src/project/tree/treeItem.ts +89 -0
- package/packages/chili-ui/src/project/tree/treeItemGroup.module.css +33 -0
- package/packages/chili-ui/src/project/tree/treeItemGroup.ts +85 -0
- package/packages/chili-ui/src/project/tree/treeModel.module.css +11 -0
- package/packages/chili-ui/src/project/tree/treeModel.ts +20 -0
- package/packages/chili-ui/src/property/check.ts +39 -0
- package/packages/chili-ui/src/property/colorPorperty.module.css +6 -0
- package/packages/chili-ui/src/property/colorProperty.ts +63 -0
- package/packages/chili-ui/src/property/common.module.css +14 -0
- package/packages/chili-ui/src/property/index.ts +4 -0
- package/packages/chili-ui/src/property/input.module.css +19 -0
- package/packages/chili-ui/src/property/input.ts +140 -0
- package/packages/chili-ui/src/property/material/index.ts +5 -0
- package/packages/chili-ui/src/property/material/materialDataContent.ts +44 -0
- package/packages/chili-ui/src/property/material/materialEditor.module.css +98 -0
- package/packages/chili-ui/src/property/material/materialEditor.ts +147 -0
- package/packages/chili-ui/src/property/material/textureEditor.module.css +46 -0
- package/packages/chili-ui/src/property/material/textureEditor.ts +61 -0
- package/packages/chili-ui/src/property/materialProperty.module.css +30 -0
- package/packages/chili-ui/src/property/materialProperty.ts +86 -0
- package/packages/chili-ui/src/property/matrixProperty.ts +147 -0
- package/packages/chili-ui/src/property/propertyBase.module.css +3 -0
- package/packages/chili-ui/src/property/propertyBase.ts +14 -0
- package/packages/chili-ui/src/property/propertyView.module.css +36 -0
- package/packages/chili-ui/src/property/propertyView.ts +115 -0
- package/packages/chili-ui/src/property/utils.ts +48 -0
- package/packages/chili-ui/src/ribbon/commandContext.module.css +73 -0
- package/packages/chili-ui/src/ribbon/commandContext.ts +239 -0
- package/packages/chili-ui/src/ribbon/index.ts +4 -0
- package/packages/chili-ui/src/ribbon/ribbon.module.css +286 -0
- package/packages/chili-ui/src/ribbon/ribbon.ts +288 -0
- package/packages/chili-ui/src/ribbon/ribbonButton.module.css +75 -0
- package/packages/chili-ui/src/ribbon/ribbonButton.ts +88 -0
- package/packages/chili-ui/src/ribbon/ribbonData.ts +66 -0
- package/packages/chili-ui/src/ribbon/ribbonStack.module.css +6 -0
- package/packages/chili-ui/src/ribbon/ribbonStack.ts +13 -0
- package/packages/chili-ui/src/ribbon/ribbonToggleButton.module.css +3 -0
- package/packages/chili-ui/src/ribbon/ribbonToggleButton.ts +6 -0
- package/packages/chili-ui/src/statusbar/index.ts +4 -0
- package/packages/chili-ui/src/statusbar/snapConfig.module.css +25 -0
- package/packages/chili-ui/src/statusbar/snapConfig.ts +92 -0
- package/packages/chili-ui/src/statusbar/statusbar.module.css +28 -0
- package/packages/chili-ui/src/statusbar/statusbar.ts +54 -0
- package/packages/chili-ui/src/toast/index.ts +4 -0
- package/packages/chili-ui/src/toast/toast.module.css +27 -0
- package/packages/chili-ui/src/toast/toast.ts +39 -0
- package/packages/chili-ui/src/viewport/flyout/flyout.module.css +9 -0
- package/packages/chili-ui/src/viewport/flyout/flyout.ts +77 -0
- package/packages/chili-ui/src/viewport/flyout/index.ts +6 -0
- package/packages/chili-ui/src/viewport/flyout/input.module.css +21 -0
- package/packages/chili-ui/src/viewport/flyout/input.ts +89 -0
- package/packages/chili-ui/src/viewport/flyout/tip.module.css +21 -0
- package/packages/chili-ui/src/viewport/flyout/tip.ts +45 -0
- package/packages/chili-ui/src/viewport/index.ts +4 -0
- package/packages/chili-ui/src/viewport/layoutViewport.module.css +21 -0
- package/packages/chili-ui/src/viewport/layoutViewport.ts +76 -0
- package/packages/chili-ui/src/viewport/viewport.module.css +179 -0
- package/packages/chili-ui/src/viewport/viewport.ts +296 -0
- package/packages/chili-vis/package.json +9 -0
- package/packages/chili-vis/src/index.ts +7 -0
- package/packages/chili-vis/src/nodeSelectionEventHandler.ts +122 -0
- package/packages/chili-vis/src/selectionEventHandler.ts +145 -0
- package/packages/chili-vis/src/shapeSelectionEventHandler.ts +176 -0
- package/packages/chili-vis/src/viewUtils.ts +64 -0
- package/packages/chili-wasm/lib/chili-wasm.d.ts +827 -0
- package/packages/chili-wasm/lib/chili-wasm.js +5275 -0
- package/packages/chili-wasm/lib/chili-wasm.wasm +0 -0
- package/packages/chili-wasm/package.json +10 -0
- package/packages/chili-wasm/src/converter.ts +124 -0
- package/packages/chili-wasm/src/curve.ts +589 -0
- package/packages/chili-wasm/src/factory.ts +331 -0
- package/packages/chili-wasm/src/geometry.ts +51 -0
- package/packages/chili-wasm/src/helper.ts +435 -0
- package/packages/chili-wasm/src/index.ts +5 -0
- package/packages/chili-wasm/src/mesher.ts +114 -0
- package/packages/chili-wasm/src/shape.ts +481 -0
- package/packages/chili-wasm/src/surface.ts +510 -0
- package/packages/chili-wasm/src/wasm.ts +13 -0
- package/packages/chili-web/package.json +9 -0
- package/packages/chili-web/src/index.ts +33 -0
- package/packages/chili-web/src/loading.ts +67 -0
- package/packages/global.d.ts +31 -0
- package/public/favicon.svg +10 -0
- package/public/fonts/fzhei.json +46120 -0
- package/public/iconfont.js +1 -0
- package/public/images/wechat.jpg +0 -0
- package/public/index.css +13 -0
- package/public/index.html +24 -0
- package/rspack.config.ts +93 -0
- package/rstest.config.ts +27 -0
- package/screenshots/screenshot.png +0 -0
- package/scripts/add_copyright.mjs +59 -0
- package/scripts/build-npm.mjs +105 -0
- package/scripts/common.mjs +24 -0
- package/scripts/release.mjs +92 -0
- package/scripts/restore-package-json.mjs +27 -0
- package/scripts/setup_wasm_deps.mjs +97 -0
- package/scripts/update-package-json.mjs +27 -0
- package/tsconfig.build.json +14 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +19 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Part of the Chili3d Project, under the AGPL-3.0 License.
|
|
2
|
+
// See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { Precision } from "../foundation/precision";
|
|
5
|
+
import { Serializer } from "../serialize";
|
|
6
|
+
import type { XYZ } from "./xyz";
|
|
7
|
+
|
|
8
|
+
@Serializer.register(["start", "end"])
|
|
9
|
+
export class LineSegment {
|
|
10
|
+
@Serializer.serialze()
|
|
11
|
+
readonly start: XYZ;
|
|
12
|
+
|
|
13
|
+
@Serializer.serialze()
|
|
14
|
+
readonly end: XYZ;
|
|
15
|
+
|
|
16
|
+
constructor(start: XYZ, end: XYZ) {
|
|
17
|
+
this.start = start;
|
|
18
|
+
this.end = end;
|
|
19
|
+
|
|
20
|
+
if (start.isEqualTo(end)) {
|
|
21
|
+
throw new Error("start and end can not be equal");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
distanceToPoint(point: XYZ): number {
|
|
26
|
+
const segmentVector = this.end.sub(this.start);
|
|
27
|
+
const pointVector = point.sub(this.start);
|
|
28
|
+
|
|
29
|
+
const segmentLengthSquared = segmentVector.dot(segmentVector);
|
|
30
|
+
const projection = pointVector.dot(segmentVector);
|
|
31
|
+
|
|
32
|
+
// Parameter t represents where the projected point lies on the segment
|
|
33
|
+
// t = 0 at start, t = 1 at end
|
|
34
|
+
const t = Math.max(0, Math.min(1, projection / segmentLengthSquared));
|
|
35
|
+
|
|
36
|
+
const closestPoint = this.start.add(segmentVector.multiply(t));
|
|
37
|
+
return point.distanceTo(closestPoint);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Calculates the shortest distance between this line segment and another line segment.
|
|
42
|
+
*
|
|
43
|
+
* This method computes the closest points on both segments and returns the distance
|
|
44
|
+
* between them along with the parametric coordinates of the closest points.
|
|
45
|
+
*
|
|
46
|
+
* Algorithm:
|
|
47
|
+
* 1. Compute direction vectors u and v for both segments
|
|
48
|
+
* 2. Calculate the discriminant D = |u|²|v|² - (u·v)² which determines if segments are parallel
|
|
49
|
+
* 3. Handle parallel and non-parallel cases separately
|
|
50
|
+
* 4. Clamp parameters to [0,1] to stay within segment bounds
|
|
51
|
+
*
|
|
52
|
+
* @param right - The other line segment to compute distance to
|
|
53
|
+
* @returns Object containing:
|
|
54
|
+
* - pointOnThis: Closest point on this segment
|
|
55
|
+
* - pointOnRight: Closest point on the other segment
|
|
56
|
+
* - distance: Euclidean distance between the closest points
|
|
57
|
+
* - sc: Parametric coordinate of closest point on this segment (0=start, 1=end)
|
|
58
|
+
* - tc: Parametric coordinate of closest point on other segment (0=start, 1=end)
|
|
59
|
+
*/
|
|
60
|
+
distanceTo(right: LineSegment) {
|
|
61
|
+
const u = this.end.sub(this.start);
|
|
62
|
+
const v = right.end.sub(right.start);
|
|
63
|
+
const w = this.start.sub(right.start);
|
|
64
|
+
|
|
65
|
+
const { sN, sD, tN, tD } = this.calculateParameters(u, v, w);
|
|
66
|
+
|
|
67
|
+
const sc = Math.abs(sN) < Precision.Float && sD !== 0 ? 0.0 : sN / sD;
|
|
68
|
+
const tc = Math.abs(tN) < Precision.Float && tD !== 0 ? 0.0 : tN / tD;
|
|
69
|
+
|
|
70
|
+
const pointOnThis = this.start.add(u.multiply(sc));
|
|
71
|
+
const pointOnRight = right.start.add(v.multiply(tc));
|
|
72
|
+
const distance = pointOnThis.distanceTo(pointOnRight);
|
|
73
|
+
|
|
74
|
+
return { pointOnThis, pointOnRight, distance, sc, tc };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
private calculateParameters(u: XYZ, v: XYZ, w: XYZ) {
|
|
78
|
+
const a = u.dot(u);
|
|
79
|
+
const b = u.dot(v);
|
|
80
|
+
const c = v.dot(v);
|
|
81
|
+
const d = u.dot(w);
|
|
82
|
+
const e = v.dot(w);
|
|
83
|
+
|
|
84
|
+
// D is the discriminant of the quadratic form used to find closest points
|
|
85
|
+
// It is proportional to the square of the sine of the angle between the two direction vectors
|
|
86
|
+
// D = |u|²|v|² - (u·v)² = |u|²|v|²(1 - cos²θ) = |u|²|v|²sin²θ
|
|
87
|
+
// When D ≈ 0, the lines are nearly parallel (sin θ ≈ 0)
|
|
88
|
+
// When D > 0, the lines are not parallel and we can find unique closest points on infinite lines
|
|
89
|
+
const D = a * c - b * b;
|
|
90
|
+
|
|
91
|
+
if (D < Precision.Float) {
|
|
92
|
+
// the lines are almost parallel
|
|
93
|
+
return this.calculateParallelSegments(a, c, d, e);
|
|
94
|
+
} else {
|
|
95
|
+
return this.calculateNonParallelSegments(D, a, b, c, d, e);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
private calculateParallelSegments(a: number, c: number, d: number, e: number) {
|
|
100
|
+
// Force using point P0 on segment S1
|
|
101
|
+
// to prevent possible division by 0.0 later
|
|
102
|
+
const sN = 0.0;
|
|
103
|
+
const sD = 1.0;
|
|
104
|
+
const tN = e;
|
|
105
|
+
const tD = c;
|
|
106
|
+
|
|
107
|
+
return this.checkParameterConstraints(tN, tD, sN, sD, -d, a);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
private calculateNonParallelSegments(D: number, a: number, b: number, c: number, d: number, e: number) {
|
|
111
|
+
let sN = b * e - c * d;
|
|
112
|
+
const sD = D; // sc = sN / sD, default sD = D >= 0
|
|
113
|
+
let tN = a * e - b * d;
|
|
114
|
+
let tD = D; // tc = tN / tD, default tD = D >= 0
|
|
115
|
+
|
|
116
|
+
if (sN < 0.0) {
|
|
117
|
+
// sc < 0 => the s=0 edge is visible
|
|
118
|
+
sN = 0.0;
|
|
119
|
+
tN = e;
|
|
120
|
+
tD = c;
|
|
121
|
+
} else if (sN > sD) {
|
|
122
|
+
// sc > 1 => the s=1 edge is visible
|
|
123
|
+
sN = sD;
|
|
124
|
+
tN = e + b;
|
|
125
|
+
tD = c;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return this.checkParameterConstraints(tN, tD, sN, sD, -d, a, b);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
private checkParameterConstraints(
|
|
132
|
+
tN: number,
|
|
133
|
+
tD: number,
|
|
134
|
+
sN: number,
|
|
135
|
+
sD: number,
|
|
136
|
+
negD: number,
|
|
137
|
+
a: number,
|
|
138
|
+
b?: number,
|
|
139
|
+
) {
|
|
140
|
+
if (tN < 0.0) {
|
|
141
|
+
// tc < 0 => the t=0 edge is visible
|
|
142
|
+
tN = 0.0;
|
|
143
|
+
if (negD < 0.0) {
|
|
144
|
+
sN = 0.0;
|
|
145
|
+
} else if (negD > a) {
|
|
146
|
+
sN = sD;
|
|
147
|
+
} else {
|
|
148
|
+
sN = negD;
|
|
149
|
+
sD = a;
|
|
150
|
+
}
|
|
151
|
+
} else if (tN > tD) {
|
|
152
|
+
// tc > 1 => the t=1 edge is visible
|
|
153
|
+
tN = tD;
|
|
154
|
+
const negDB = b !== undefined ? negD + b : negD;
|
|
155
|
+
if (negDB < 0.0) {
|
|
156
|
+
sN = 0.0;
|
|
157
|
+
} else if (negDB > a) {
|
|
158
|
+
sN = sD;
|
|
159
|
+
} else {
|
|
160
|
+
sN = negDB;
|
|
161
|
+
sD = a;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return { tN, tD, sN, sD };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
// Part of the Chili3d Project, under the AGPL-3.0 License.
|
|
2
|
+
// See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { Precision } from "../foundation";
|
|
5
|
+
|
|
6
|
+
export class MathUtils {
|
|
7
|
+
static degToRad(degrees: number) {
|
|
8
|
+
return degrees * (Math.PI / 180);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
static radToDeg(radians: number) {
|
|
12
|
+
return radians * (180 / Math.PI);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
static anyEqualZero(...values: number[]) {
|
|
16
|
+
return values.some((value) => Math.abs(value) < Precision.Float);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
static allEqualZero(...values: number[]) {
|
|
20
|
+
return values.every((value) => Math.abs(value) < Precision.Float);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static almostEqual(a: number, b: number, tolerance = 1e-6) {
|
|
24
|
+
return Math.abs(a - b) < tolerance;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static clamp(value: number, min: number, max: number) {
|
|
28
|
+
return Math.max(min, Math.min(max, value));
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static minMax(values: ArrayLike<number>) {
|
|
32
|
+
if (values.length === 0) return undefined;
|
|
33
|
+
|
|
34
|
+
let min = values[0];
|
|
35
|
+
let max = values[0];
|
|
36
|
+
|
|
37
|
+
for (let i = 1; i < values.length; i++) {
|
|
38
|
+
const value = values[i];
|
|
39
|
+
if (value < min) min = value;
|
|
40
|
+
if (value > max) max = value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { min, max };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
// Part of the Chili3d Project, under the AGPL-3.0 License.
|
|
2
|
+
// See LICENSE file in the project root for full license information.
|
|
3
|
+
|
|
4
|
+
import { Serializer } from "../serialize";
|
|
5
|
+
import { MathUtils } from "./mathUtils";
|
|
6
|
+
import type { Plane } from "./plane";
|
|
7
|
+
import { Quaternion } from "./quaternion";
|
|
8
|
+
import { XYZ, type XYZLike } from "./xyz";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Matrix in column-major order
|
|
12
|
+
*/
|
|
13
|
+
@Serializer.register(["array"], (array: Float32Array) => {
|
|
14
|
+
return Matrix4.fromArray(array);
|
|
15
|
+
})
|
|
16
|
+
export class Matrix4 {
|
|
17
|
+
private readonly _array: Float32Array = new Float32Array(16);
|
|
18
|
+
@Serializer.serialze()
|
|
19
|
+
get array(): ReadonlyArray<number> {
|
|
20
|
+
return [...this._array];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public determinant(): number {
|
|
24
|
+
const [a00, a01, a02, a03] = [this._array[0], this._array[1], this._array[2], this._array[3]];
|
|
25
|
+
const [a10, a11, a12, a13] = [this._array[4], this._array[5], this._array[6], this._array[7]];
|
|
26
|
+
const [a20, a21, a22, a23] = [this._array[8], this._array[9], this._array[10], this._array[11]];
|
|
27
|
+
const [a30, a31, a32, a33] = [this._array[12], this._array[13], this._array[14], this._array[15]];
|
|
28
|
+
|
|
29
|
+
const b0 = a00 * a11 - a01 * a10;
|
|
30
|
+
const b1 = a00 * a12 - a02 * a10;
|
|
31
|
+
const b2 = a01 * a12 - a02 * a11;
|
|
32
|
+
const b3 = a20 * a31 - a21 * a30;
|
|
33
|
+
const b4 = a20 * a32 - a22 * a30;
|
|
34
|
+
const b5 = a21 * a32 - a22 * a31;
|
|
35
|
+
const b6 = a00 * b5 - a01 * b4 + a02 * b3;
|
|
36
|
+
const b7 = a10 * b5 - a11 * b4 + a12 * b3;
|
|
37
|
+
const b8 = a20 * b2 - a21 * b1 + a22 * b0;
|
|
38
|
+
const b9 = a30 * b2 - a31 * b1 + a32 * b0;
|
|
39
|
+
|
|
40
|
+
return a13 * b6 - a03 * b7 + a33 * b8 - a23 * b9;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public toArray(): readonly number[] {
|
|
44
|
+
return [...this._array];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public add(other: Matrix4): Matrix4 {
|
|
48
|
+
const result = new Matrix4();
|
|
49
|
+
for (let index = 0; index < 16; index++) {
|
|
50
|
+
result._array[index] = this._array[index] + other._array[index];
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public invert(): Matrix4 | undefined {
|
|
56
|
+
const [a00, a01, a02, a03] = [this._array[0], this._array[1], this._array[2], this._array[3]];
|
|
57
|
+
const [a10, a11, a12, a13] = [this._array[4], this._array[5], this._array[6], this._array[7]];
|
|
58
|
+
const [a20, a21, a22, a23] = [this._array[8], this._array[9], this._array[10], this._array[11]];
|
|
59
|
+
const [a30, a31, a32, a33] = [this._array[12], this._array[13], this._array[14], this._array[15]];
|
|
60
|
+
const b00 = a00 * a11 - a01 * a10;
|
|
61
|
+
const b01 = a00 * a12 - a02 * a10;
|
|
62
|
+
const b02 = a00 * a13 - a03 * a10;
|
|
63
|
+
const b03 = a01 * a12 - a02 * a11;
|
|
64
|
+
const b04 = a01 * a13 - a03 * a11;
|
|
65
|
+
const b05 = a02 * a13 - a03 * a12;
|
|
66
|
+
const b06 = a20 * a31 - a21 * a30;
|
|
67
|
+
const b07 = a20 * a32 - a22 * a30;
|
|
68
|
+
const b08 = a20 * a33 - a23 * a30;
|
|
69
|
+
const b09 = a21 * a32 - a22 * a31;
|
|
70
|
+
const b10 = a21 * a33 - a23 * a31;
|
|
71
|
+
const b11 = a22 * a33 - a23 * a32;
|
|
72
|
+
|
|
73
|
+
let det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
|
|
74
|
+
if (det === 0) return undefined;
|
|
75
|
+
det = 1.0 / det;
|
|
76
|
+
|
|
77
|
+
return Matrix4.fromArray([
|
|
78
|
+
(a11 * b11 - a12 * b10 + a13 * b09) * det,
|
|
79
|
+
(a02 * b10 - a01 * b11 - a03 * b09) * det,
|
|
80
|
+
(a31 * b05 - a32 * b04 + a33 * b03) * det,
|
|
81
|
+
(a22 * b04 - a21 * b05 - a23 * b03) * det,
|
|
82
|
+
(a12 * b08 - a10 * b11 - a13 * b07) * det,
|
|
83
|
+
(a00 * b11 - a02 * b08 + a03 * b07) * det,
|
|
84
|
+
(a32 * b02 - a30 * b05 - a33 * b01) * det,
|
|
85
|
+
(a20 * b05 - a22 * b02 + a23 * b01) * det,
|
|
86
|
+
(a10 * b10 - a11 * b08 + a13 * b06) * det,
|
|
87
|
+
(a01 * b08 - a00 * b10 - a03 * b06) * det,
|
|
88
|
+
(a30 * b04 - a31 * b02 + a33 * b00) * det,
|
|
89
|
+
(a21 * b02 - a20 * b04 - a23 * b00) * det,
|
|
90
|
+
(a11 * b07 - a10 * b09 - a12 * b06) * det,
|
|
91
|
+
(a00 * b09 - a01 * b07 + a02 * b06) * det,
|
|
92
|
+
(a31 * b01 - a30 * b03 - a32 * b00) * det,
|
|
93
|
+
(a20 * b03 - a21 * b01 + a22 * b00) * det,
|
|
94
|
+
]);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
public multiply(other: Matrix4): Matrix4 {
|
|
98
|
+
const array = new Array(16).fill(0);
|
|
99
|
+
for (let i = 0; i < 4; i++) {
|
|
100
|
+
for (let j = 0; j < 4; j++) {
|
|
101
|
+
for (let k = 0; k < 4; k++) {
|
|
102
|
+
array[i * 4 + j] += this._array[i * 4 + k] * other._array[k * 4 + j];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return Matrix4.fromArray(array);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
public equals(value: Matrix4): boolean {
|
|
110
|
+
for (let i = 0; i < 16; i++) {
|
|
111
|
+
if (!MathUtils.almostEqual(this._array[i], value._array[i])) return false;
|
|
112
|
+
}
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
public clone(): Matrix4 {
|
|
117
|
+
return Matrix4.fromArray([...this._array]);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public static fromArray(array: ArrayLike<number>): Matrix4 {
|
|
121
|
+
const result = new Matrix4();
|
|
122
|
+
for (let index = 0; index < 16; index++) {
|
|
123
|
+
result._array[index] = array[index];
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public static identity(): Matrix4 {
|
|
129
|
+
return Matrix4.fromArray([
|
|
130
|
+
1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0,
|
|
131
|
+
]);
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
public static zero(): Matrix4 {
|
|
135
|
+
return Matrix4.fromArray(new Array(16).fill(0));
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
public static fromEuler(x: number, y: number, z: number): Matrix4 {
|
|
139
|
+
const cx = Math.cos(x);
|
|
140
|
+
const sx = Math.sin(x);
|
|
141
|
+
const cy = Math.cos(y);
|
|
142
|
+
const sy = Math.sin(y);
|
|
143
|
+
const cz = Math.cos(z);
|
|
144
|
+
const sz = Math.sin(z);
|
|
145
|
+
return Matrix4.fromArray([
|
|
146
|
+
cy * cz,
|
|
147
|
+
cx * sz + sx * sy * cz,
|
|
148
|
+
sx * sz - cx * sy * cz,
|
|
149
|
+
0,
|
|
150
|
+
-cy * sz,
|
|
151
|
+
cx * cz - sx * sy * sz,
|
|
152
|
+
sx * cz + cx * sy * sz,
|
|
153
|
+
0,
|
|
154
|
+
sy,
|
|
155
|
+
-sx * cy,
|
|
156
|
+
cx * cy,
|
|
157
|
+
0,
|
|
158
|
+
0,
|
|
159
|
+
0,
|
|
160
|
+
0,
|
|
161
|
+
1,
|
|
162
|
+
]);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
public static fromAxisRad(position: XYZLike, normal: XYZLike, radians: number): Matrix4 {
|
|
166
|
+
const axes = Quaternion.fromAxisAngle(normal, radians).toAxes();
|
|
167
|
+
|
|
168
|
+
const { x, y, z } = position;
|
|
169
|
+
return Matrix4.fromTranslation(-x, -y, -z).multiply(Matrix4.fromArray([...axes, x, y, z, 1]));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
public static fromScale(x: number, y: number, z: number): Matrix4 {
|
|
173
|
+
return Matrix4.fromArray([x, 0, 0, 0, 0, y, 0, 0, 0, 0, z, 0, 0, 0, 0, 1]);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
public static fromTranslation(x: number, y: number, z: number): Matrix4 {
|
|
177
|
+
return Matrix4.fromArray([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, x, y, z, 1.0]);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
public static createMirrorWithPlane(plane: Plane): Matrix4 {
|
|
181
|
+
const d = -plane.origin.dot(plane.normal);
|
|
182
|
+
const x = plane.normal.x;
|
|
183
|
+
const y = plane.normal.y;
|
|
184
|
+
const z = plane.normal.z;
|
|
185
|
+
const temp = -2 * x;
|
|
186
|
+
const temp2 = -2 * y;
|
|
187
|
+
const temp3 = -2 * z;
|
|
188
|
+
return Matrix4.fromArray([
|
|
189
|
+
temp * x + 1,
|
|
190
|
+
temp2 * x,
|
|
191
|
+
temp3 * x,
|
|
192
|
+
0.0,
|
|
193
|
+
temp * y,
|
|
194
|
+
temp2 * y + 1,
|
|
195
|
+
temp3 * y,
|
|
196
|
+
0.0,
|
|
197
|
+
temp * z,
|
|
198
|
+
temp2 * z,
|
|
199
|
+
temp3 * z + 1,
|
|
200
|
+
0.0,
|
|
201
|
+
temp * d,
|
|
202
|
+
temp2 * d,
|
|
203
|
+
temp3 * d,
|
|
204
|
+
1.0,
|
|
205
|
+
]);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
public transpose(): Matrix4 {
|
|
209
|
+
const result = new Matrix4();
|
|
210
|
+
result._array[0] = this._array[0];
|
|
211
|
+
result._array[1] = this._array[4];
|
|
212
|
+
result._array[2] = this._array[8];
|
|
213
|
+
result._array[3] = this._array[12];
|
|
214
|
+
|
|
215
|
+
result._array[4] = this._array[1];
|
|
216
|
+
result._array[5] = this._array[5];
|
|
217
|
+
result._array[6] = this._array[9];
|
|
218
|
+
result._array[7] = this._array[13];
|
|
219
|
+
|
|
220
|
+
result._array[8] = this._array[2];
|
|
221
|
+
result._array[9] = this._array[6];
|
|
222
|
+
result._array[10] = this._array[10];
|
|
223
|
+
result._array[11] = this._array[14];
|
|
224
|
+
|
|
225
|
+
result._array[12] = this._array[3];
|
|
226
|
+
result._array[13] = this._array[7];
|
|
227
|
+
result._array[14] = this._array[11];
|
|
228
|
+
result._array[15] = this._array[15];
|
|
229
|
+
|
|
230
|
+
return result;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
ofPoints(points: ArrayLike<number>): number[] {
|
|
234
|
+
const result: number[] = [];
|
|
235
|
+
for (let i = 0; i < points.length / 3; i++) {
|
|
236
|
+
const x =
|
|
237
|
+
points[3 * i] * this._array[0] +
|
|
238
|
+
points[3 * i + 1] * this._array[4] +
|
|
239
|
+
points[3 * i + 2] * this._array[8] +
|
|
240
|
+
this._array[12];
|
|
241
|
+
const y =
|
|
242
|
+
points[3 * i] * this._array[1] +
|
|
243
|
+
points[3 * i + 1] * this._array[5] +
|
|
244
|
+
points[3 * i + 2] * this._array[9] +
|
|
245
|
+
this._array[13];
|
|
246
|
+
const z =
|
|
247
|
+
points[3 * i] * this._array[2] +
|
|
248
|
+
points[3 * i + 1] * this._array[6] +
|
|
249
|
+
points[3 * i + 2] * this._array[10] +
|
|
250
|
+
this._array[14];
|
|
251
|
+
const w =
|
|
252
|
+
points[3 * i] * this._array[3] +
|
|
253
|
+
points[3 * i + 1] * this._array[7] +
|
|
254
|
+
points[3 * i + 2] * this._array[11] +
|
|
255
|
+
this._array[15];
|
|
256
|
+
result.push(x / w, y / w, z / w);
|
|
257
|
+
}
|
|
258
|
+
return result;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
public ofPoint(point: XYZLike): XYZ {
|
|
262
|
+
const result = this.ofPoints([point.x, point.y, point.z]);
|
|
263
|
+
return new XYZ(result[0], result[1], result[2]);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
public ofVector(vector: XYZLike): XYZ {
|
|
267
|
+
const result = this.ofVectors([vector.x, vector.y, vector.z]);
|
|
268
|
+
return new XYZ(result[0], result[1], result[2]);
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
public ofVectors(vectors: ArrayLike<number>): number[] {
|
|
272
|
+
const result: number[] = [];
|
|
273
|
+
for (let i = 0; i < vectors.length / 3; i++) {
|
|
274
|
+
const x =
|
|
275
|
+
vectors[3 * i] * this._array[0] +
|
|
276
|
+
vectors[3 * i + 1] * this._array[4] +
|
|
277
|
+
vectors[3 * i + 2] * this._array[8];
|
|
278
|
+
const y =
|
|
279
|
+
vectors[3 * i] * this._array[1] +
|
|
280
|
+
vectors[3 * i + 1] * this._array[5] +
|
|
281
|
+
vectors[3 * i + 2] * this._array[9];
|
|
282
|
+
const z =
|
|
283
|
+
vectors[3 * i] * this._array[2] +
|
|
284
|
+
vectors[3 * i + 1] * this._array[6] +
|
|
285
|
+
vectors[3 * i + 2] * this._array[10];
|
|
286
|
+
result.push(x, y, z);
|
|
287
|
+
}
|
|
288
|
+
return result;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
public translationPart(): XYZ {
|
|
292
|
+
return new XYZ(this._array[12], this._array[13], this._array[14]);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
public getScale(): XYZ {
|
|
296
|
+
const x = Math.hypot(this._array[0], this._array[1], this._array[2]);
|
|
297
|
+
const y = Math.hypot(this._array[4], this._array[5], this._array[6]);
|
|
298
|
+
const z = Math.hypot(this._array[8], this._array[9], this._array[10]);
|
|
299
|
+
return new XYZ(x, y, z);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
public getEulerAngles(): { pitch: number; yaw: number; roll: number } {
|
|
303
|
+
const m = this._array;
|
|
304
|
+
const m11 = m[0],
|
|
305
|
+
m12 = m[4],
|
|
306
|
+
m13 = m[8];
|
|
307
|
+
const m22 = m[5],
|
|
308
|
+
m23 = m[9];
|
|
309
|
+
const m32 = m[6],
|
|
310
|
+
m33 = m[10];
|
|
311
|
+
|
|
312
|
+
let pitch = 0;
|
|
313
|
+
const yaw = Math.asin(MathUtils.clamp(m13, -1, 1));
|
|
314
|
+
let roll = 0;
|
|
315
|
+
|
|
316
|
+
if (Math.abs(m13) < 0.9999999) {
|
|
317
|
+
pitch = Math.atan2(-m23, m33);
|
|
318
|
+
roll = Math.atan2(-m12, m11);
|
|
319
|
+
} else {
|
|
320
|
+
pitch = Math.atan2(m32, m22);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return { pitch, yaw, roll };
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
public static createFromTRS(
|
|
327
|
+
position: XYZLike,
|
|
328
|
+
rotation: { pitch: number; yaw: number; roll: number },
|
|
329
|
+
scale: XYZLike,
|
|
330
|
+
): Matrix4 {
|
|
331
|
+
const quaternion = Quaternion.fromEuler(rotation.pitch, rotation.yaw, rotation.roll);
|
|
332
|
+
const te = new Array(16).fill(0);
|
|
333
|
+
|
|
334
|
+
const x = quaternion.x,
|
|
335
|
+
y = quaternion.y,
|
|
336
|
+
z = quaternion.z,
|
|
337
|
+
w = quaternion.w;
|
|
338
|
+
const x2 = x + x,
|
|
339
|
+
y2 = y + y,
|
|
340
|
+
z2 = z + z;
|
|
341
|
+
const xx = x * x2,
|
|
342
|
+
xy = x * y2,
|
|
343
|
+
xz = x * z2;
|
|
344
|
+
const yy = y * y2,
|
|
345
|
+
yz = y * z2,
|
|
346
|
+
zz = z * z2;
|
|
347
|
+
const wx = w * x2,
|
|
348
|
+
wy = w * y2,
|
|
349
|
+
wz = w * z2;
|
|
350
|
+
|
|
351
|
+
const sx = scale.x,
|
|
352
|
+
sy = scale.y,
|
|
353
|
+
sz = scale.z;
|
|
354
|
+
|
|
355
|
+
te[0] = (1 - (yy + zz)) * sx;
|
|
356
|
+
te[1] = (xy + wz) * sx;
|
|
357
|
+
te[2] = (xz - wy) * sx;
|
|
358
|
+
te[3] = 0;
|
|
359
|
+
|
|
360
|
+
te[4] = (xy - wz) * sy;
|
|
361
|
+
te[5] = (1 - (xx + zz)) * sy;
|
|
362
|
+
te[6] = (yz + wx) * sy;
|
|
363
|
+
te[7] = 0;
|
|
364
|
+
|
|
365
|
+
te[8] = (xz + wy) * sz;
|
|
366
|
+
te[9] = (yz - wx) * sz;
|
|
367
|
+
te[10] = (1 - (xx + yy)) * sz;
|
|
368
|
+
te[11] = 0;
|
|
369
|
+
|
|
370
|
+
te[12] = position.x;
|
|
371
|
+
te[13] = position.y;
|
|
372
|
+
te[14] = position.z;
|
|
373
|
+
te[15] = 1;
|
|
374
|
+
|
|
375
|
+
return Matrix4.fromArray(te);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
public static fromQuaternion(qua: Quaternion): Matrix4 {
|
|
379
|
+
const x2 = qua.x * qua.x;
|
|
380
|
+
const y2 = qua.y * qua.y;
|
|
381
|
+
const z2 = qua.z * qua.z;
|
|
382
|
+
|
|
383
|
+
const xx2 = x2 * qua.x;
|
|
384
|
+
const xy2 = x2 * qua.y;
|
|
385
|
+
const xz2 = x2 * qua.z;
|
|
386
|
+
|
|
387
|
+
const yy2 = y2 * qua.y;
|
|
388
|
+
const yz2 = y2 * qua.z;
|
|
389
|
+
const zz2 = z2 * qua.z;
|
|
390
|
+
|
|
391
|
+
const sy2 = y2 * qua.w;
|
|
392
|
+
const sz2 = z2 * qua.w;
|
|
393
|
+
const sx2 = x2 * qua.w;
|
|
394
|
+
|
|
395
|
+
return Matrix4.fromArray([
|
|
396
|
+
1 - yy2 - zz2,
|
|
397
|
+
xy2 + sz2,
|
|
398
|
+
xz2 - sy2,
|
|
399
|
+
0,
|
|
400
|
+
xy2 - sz2,
|
|
401
|
+
1 - xx2 - zz2,
|
|
402
|
+
yz2 + sx2,
|
|
403
|
+
0,
|
|
404
|
+
xz2 + sy2,
|
|
405
|
+
yz2 - sx2,
|
|
406
|
+
1 - xx2 - yy2,
|
|
407
|
+
0,
|
|
408
|
+
0,
|
|
409
|
+
0,
|
|
410
|
+
0,
|
|
411
|
+
1,
|
|
412
|
+
]);
|
|
413
|
+
}
|
|
414
|
+
}
|