sdl-mcp 0.12.2 → 0.12.3
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/README.md +10 -0
- package/config/sdlmcp.config.example.json +53 -8
- package/config/sdlmcp.config.schema.json +530 -106
- package/dist/.tsbuildinfo +1 -1
- package/dist/benchmark/external-manifest.d.ts +162 -0
- package/dist/benchmark/external-manifest.d.ts.map +1 -0
- package/dist/benchmark/external-manifest.js +336 -0
- package/dist/benchmark/external-manifest.js.map +1 -0
- package/dist/benchmark/external-runner.d.ts +100 -0
- package/dist/benchmark/external-runner.d.ts.map +1 -0
- package/dist/benchmark/external-runner.js +1171 -0
- package/dist/benchmark/external-runner.js.map +1 -0
- package/dist/benchmark/output-file.d.ts +3 -0
- package/dist/benchmark/output-file.d.ts.map +1 -0
- package/dist/benchmark/output-file.js +8 -0
- package/dist/benchmark/output-file.js.map +1 -0
- package/dist/cli/argParsing.d.ts.map +1 -1
- package/dist/cli/argParsing.js +6 -0
- package/dist/cli/argParsing.js.map +1 -1
- package/dist/cli/commands/benchmark.d.ts.map +1 -1
- package/dist/cli/commands/benchmark.js +3 -2
- package/dist/cli/commands/benchmark.js.map +1 -1
- package/dist/cli/commands/index.d.ts +1 -0
- package/dist/cli/commands/index.d.ts.map +1 -1
- package/dist/cli/commands/index.js +13 -7
- package/dist/cli/commands/index.js.map +1 -1
- package/dist/cli/commands/init.d.ts +5 -1
- package/dist/cli/commands/init.d.ts.map +1 -1
- package/dist/cli/commands/init.js +73 -3
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/serve.d.ts.map +1 -1
- package/dist/cli/commands/serve.js +2 -0
- package/dist/cli/commands/serve.js.map +1 -1
- package/dist/cli/index.js +2 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/cli/transport/http.d.ts +1 -35
- package/dist/cli/transport/http.d.ts.map +1 -1
- package/dist/cli/transport/http.js +151 -175
- package/dist/cli/transport/http.js.map +1 -1
- package/dist/cli/types.d.ts +1 -0
- package/dist/cli/types.d.ts.map +1 -1
- package/dist/config/constants.d.ts +30 -0
- package/dist/config/constants.d.ts.map +1 -1
- package/dist/config/constants.js +30 -0
- package/dist/config/constants.js.map +1 -1
- package/dist/config/types.d.ts +53 -1
- package/dist/config/types.d.ts.map +1 -1
- package/dist/config/types.js +62 -14
- package/dist/config/types.js.map +1 -1
- package/dist/db/ladybug-batching.d.ts +1 -0
- package/dist/db/ladybug-batching.d.ts.map +1 -1
- package/dist/db/ladybug-batching.js +1 -0
- package/dist/db/ladybug-batching.js.map +1 -1
- package/dist/db/ladybug-core.d.ts +3 -0
- package/dist/db/ladybug-core.d.ts.map +1 -1
- package/dist/db/ladybug-core.js +72 -2
- package/dist/db/ladybug-core.js.map +1 -1
- package/dist/db/ladybug-embeddings.d.ts +6 -1
- package/dist/db/ladybug-embeddings.d.ts.map +1 -1
- package/dist/db/ladybug-embeddings.js +6 -1
- package/dist/db/ladybug-embeddings.js.map +1 -1
- package/dist/db/ladybug-file-summaries.d.ts.map +1 -1
- package/dist/db/ladybug-file-summaries.js +23 -0
- package/dist/db/ladybug-file-summaries.js.map +1 -1
- package/dist/db/ladybug-queries.js +1 -1
- package/dist/db/ladybug-queries.js.map +1 -1
- package/dist/db/migrations/index.d.ts.map +1 -1
- package/dist/db/migrations/index.js +2 -0
- package/dist/db/migrations/index.js.map +1 -1
- package/dist/db/migrations/m007-copy-embeddings-to-symbol.d.ts +5 -9
- package/dist/db/migrations/m007-copy-embeddings-to-symbol.d.ts.map +1 -1
- package/dist/db/migrations/m007-copy-embeddings-to-symbol.js +24 -126
- package/dist/db/migrations/m007-copy-embeddings-to-symbol.js.map +1 -1
- package/dist/db/migrations/m021-remediate-symbol-embeddings.d.ts +5 -0
- package/dist/db/migrations/m021-remediate-symbol-embeddings.d.ts.map +1 -0
- package/dist/db/migrations/m021-remediate-symbol-embeddings.js +7 -0
- package/dist/db/migrations/m021-remediate-symbol-embeddings.js.map +1 -0
- package/dist/db/migrations/symbol-embedding-remediation.d.ts +57 -0
- package/dist/db/migrations/symbol-embedding-remediation.d.ts.map +1 -0
- package/dist/db/migrations/symbol-embedding-remediation.js +335 -0
- package/dist/db/migrations/symbol-embedding-remediation.js.map +1 -0
- package/dist/graph/layout/force-layout.d.ts +4 -0
- package/dist/graph/layout/force-layout.d.ts.map +1 -0
- package/dist/graph/layout/force-layout.js +127 -0
- package/dist/graph/layout/force-layout.js.map +1 -0
- package/dist/graph/layout/layout-service.d.ts +37 -0
- package/dist/graph/layout/layout-service.d.ts.map +1 -0
- package/dist/graph/layout/layout-service.js +172 -0
- package/dist/graph/layout/layout-service.js.map +1 -0
- package/dist/graph/layout/native-engine.d.ts +9 -0
- package/dist/graph/layout/native-engine.d.ts.map +1 -0
- package/dist/graph/layout/native-engine.js +59 -0
- package/dist/graph/layout/native-engine.js.map +1 -0
- package/dist/graph/layout/prng.d.ts +3 -0
- package/dist/graph/layout/prng.d.ts.map +1 -0
- package/dist/graph/layout/prng.js +19 -0
- package/dist/graph/layout/prng.js.map +1 -0
- package/dist/graph/layout/serializer.d.ts +3 -0
- package/dist/graph/layout/serializer.d.ts.map +1 -0
- package/dist/graph/layout/serializer.js +20 -0
- package/dist/graph/layout/serializer.js.map +1 -0
- package/dist/graph/layout/types.d.ts +30 -0
- package/dist/graph/layout/types.d.ts.map +1 -0
- package/dist/graph/layout/types.js +2 -0
- package/dist/graph/layout/types.js.map +1 -0
- package/dist/indexer/embeddings.d.ts +7 -0
- package/dist/indexer/embeddings.d.ts.map +1 -1
- package/dist/indexer/embeddings.js +44 -4
- package/dist/indexer/embeddings.js.map +1 -1
- package/dist/indexer/file-summary-embeddings.d.ts +12 -0
- package/dist/indexer/file-summary-embeddings.d.ts.map +1 -1
- package/dist/indexer/file-summary-embeddings.js +83 -21
- package/dist/indexer/file-summary-embeddings.js.map +1 -1
- package/dist/indexer/fileWalker.d.ts.map +1 -1
- package/dist/indexer/fileWalker.js +2 -1
- package/dist/indexer/fileWalker.js.map +1 -1
- package/dist/indexer/metrics-updater.d.ts.map +1 -1
- package/dist/indexer/metrics-updater.js +27 -4
- package/dist/indexer/metrics-updater.js.map +1 -1
- package/dist/indexer/watcher.d.ts.map +1 -1
- package/dist/indexer/watcher.js +2 -1
- package/dist/indexer/watcher.js.map +1 -1
- package/dist/mcp/context-response-projection.d.ts.map +1 -1
- package/dist/mcp/context-response-projection.js +49 -13
- package/dist/mcp/context-response-projection.js.map +1 -1
- package/dist/mcp/tools/search-edit/planner.d.ts.map +1 -1
- package/dist/mcp/tools/search-edit/planner.js +10 -3
- package/dist/mcp/tools/search-edit/planner.js.map +1 -1
- package/dist/observability/event-tap.d.ts +2 -1
- package/dist/observability/event-tap.d.ts.map +1 -1
- package/dist/observability/event-tap.js.map +1 -1
- package/dist/observability/service.d.ts +11 -4
- package/dist/observability/service.d.ts.map +1 -1
- package/dist/observability/service.js +83 -13
- package/dist/observability/service.js.map +1 -1
- package/dist/observability/types.d.ts +48 -2
- package/dist/observability/types.d.ts.map +1 -1
- package/dist/ui/.tsbuildinfo +1 -0
- package/dist/ui/vendor/fflate.js +2692 -0
- package/dist/ui/vendor/jsm/controls/ArcballControls.js +3543 -0
- package/dist/ui/vendor/jsm/controls/DragControls.js +452 -0
- package/dist/ui/vendor/jsm/controls/FirstPersonControls.js +488 -0
- package/dist/ui/vendor/jsm/controls/FlyControls.js +384 -0
- package/dist/ui/vendor/jsm/controls/MapControls.js +116 -0
- package/dist/ui/vendor/jsm/controls/OrbitControls.js +1963 -0
- package/dist/ui/vendor/jsm/controls/PointerLockControls.js +264 -0
- package/dist/ui/vendor/jsm/controls/TrackballControls.js +1001 -0
- package/dist/ui/vendor/jsm/controls/TransformControls.js +2003 -0
- package/dist/ui/vendor/jsm/loaders/3DMLoader.js +1836 -0
- package/dist/ui/vendor/jsm/loaders/3MFLoader.js +1621 -0
- package/dist/ui/vendor/jsm/loaders/AMFLoader.js +541 -0
- package/dist/ui/vendor/jsm/loaders/BVHLoader.js +484 -0
- package/dist/ui/vendor/jsm/loaders/ColladaLoader.js +153 -0
- package/dist/ui/vendor/jsm/loaders/DDSLoader.js +385 -0
- package/dist/ui/vendor/jsm/loaders/DRACOLoader.js +772 -0
- package/dist/ui/vendor/jsm/loaders/EXRLoader.js +3395 -0
- package/dist/ui/vendor/jsm/loaders/FBXLoader.js +4580 -0
- package/dist/ui/vendor/jsm/loaders/FontLoader.js +260 -0
- package/dist/ui/vendor/jsm/loaders/GCodeLoader.js +318 -0
- package/dist/ui/vendor/jsm/loaders/GLTFLoader.js +4860 -0
- package/dist/ui/vendor/jsm/loaders/HDRCubeTextureLoader.js +164 -0
- package/dist/ui/vendor/jsm/loaders/HDRLoader.js +463 -0
- package/dist/ui/vendor/jsm/loaders/IESLoader.js +379 -0
- package/dist/ui/vendor/jsm/loaders/KMZLoader.js +163 -0
- package/dist/ui/vendor/jsm/loaders/KTX2Loader.js +1276 -0
- package/dist/ui/vendor/jsm/loaders/KTXLoader.js +197 -0
- package/dist/ui/vendor/jsm/loaders/LDrawLoader.js +2510 -0
- package/dist/ui/vendor/jsm/loaders/LUT3dlLoader.js +205 -0
- package/dist/ui/vendor/jsm/loaders/LUTCubeLoader.js +190 -0
- package/dist/ui/vendor/jsm/loaders/LUTImageLoader.js +190 -0
- package/dist/ui/vendor/jsm/loaders/LWOLoader.js +1051 -0
- package/dist/ui/vendor/jsm/loaders/LottieLoader.js +130 -0
- package/dist/ui/vendor/jsm/loaders/MD2Loader.js +435 -0
- package/dist/ui/vendor/jsm/loaders/MDDLoader.js +147 -0
- package/dist/ui/vendor/jsm/loaders/MTLLoader.js +593 -0
- package/dist/ui/vendor/jsm/loaders/MaterialXLoader.js +1126 -0
- package/dist/ui/vendor/jsm/loaders/NRRDLoader.js +718 -0
- package/dist/ui/vendor/jsm/loaders/OBJLoader.js +955 -0
- package/dist/ui/vendor/jsm/loaders/PCDLoader.js +620 -0
- package/dist/ui/vendor/jsm/loaders/PDBLoader.js +272 -0
- package/dist/ui/vendor/jsm/loaders/PLYLoader.js +968 -0
- package/dist/ui/vendor/jsm/loaders/PVRLoader.js +270 -0
- package/dist/ui/vendor/jsm/loaders/RGBELoader.js +18 -0
- package/dist/ui/vendor/jsm/loaders/STLLoader.js +421 -0
- package/dist/ui/vendor/jsm/loaders/SVGLoader.js +3319 -0
- package/dist/ui/vendor/jsm/loaders/TDSLoader.js +1142 -0
- package/dist/ui/vendor/jsm/loaders/TGALoader.js +538 -0
- package/dist/ui/vendor/jsm/loaders/TIFFLoader.js +59 -0
- package/dist/ui/vendor/jsm/loaders/TTFLoader.js +261 -0
- package/dist/ui/vendor/jsm/loaders/USDLoader.js +303 -0
- package/dist/ui/vendor/jsm/loaders/USDZLoader.js +16 -0
- package/dist/ui/vendor/jsm/loaders/UltraHDRLoader.js +755 -0
- package/dist/ui/vendor/jsm/loaders/VOXLoader.js +919 -0
- package/dist/ui/vendor/jsm/loaders/VRMLLoader.js +3646 -0
- package/dist/ui/vendor/jsm/loaders/VTKLoader.js +1293 -0
- package/dist/ui/vendor/jsm/loaders/XYZLoader.js +143 -0
- package/dist/ui/vendor/jsm/loaders/collada/ColladaComposer.js +3044 -0
- package/dist/ui/vendor/jsm/loaders/collada/ColladaParser.js +1977 -0
- package/dist/ui/vendor/jsm/loaders/lwo/IFFParser.js +1217 -0
- package/dist/ui/vendor/jsm/loaders/lwo/LWO2Parser.js +414 -0
- package/dist/ui/vendor/jsm/loaders/lwo/LWO3Parser.js +373 -0
- package/dist/ui/vendor/jsm/loaders/usd/USDAParser.js +901 -0
- package/dist/ui/vendor/jsm/loaders/usd/USDCParser.js +1878 -0
- package/dist/ui/vendor/jsm/loaders/usd/USDComposer.js +4627 -0
- package/dist/ui/vendor/jsm/utils/BufferGeometryUtils.js +1501 -0
- package/dist/ui/vendor/jsm/utils/CameraUtils.js +82 -0
- package/dist/ui/vendor/jsm/utils/ColorUtils.js +76 -0
- package/dist/ui/vendor/jsm/utils/GeometryCompressionUtils.js +547 -0
- package/dist/ui/vendor/jsm/utils/GeometryUtils.js +226 -0
- package/dist/ui/vendor/jsm/utils/LDrawUtils.js +211 -0
- package/dist/ui/vendor/jsm/utils/SceneOptimizer.js +458 -0
- package/dist/ui/vendor/jsm/utils/SceneUtils.js +363 -0
- package/dist/ui/vendor/jsm/utils/ShadowMapViewer.js +244 -0
- package/dist/ui/vendor/jsm/utils/ShadowMapViewerGPU.js +233 -0
- package/dist/ui/vendor/jsm/utils/SkeletonUtils.js +496 -0
- package/dist/ui/vendor/jsm/utils/SortUtils.js +175 -0
- package/dist/ui/vendor/jsm/utils/UVsDebug.js +173 -0
- package/dist/ui/vendor/jsm/utils/WebGLTextureUtils.js +115 -0
- package/dist/ui/vendor/jsm/utils/WebGPUTextureUtils.js +81 -0
- package/dist/ui/vendor/jsm/utils/WorkerPool.js +167 -0
- package/dist/ui/vendor/three.core.min.js +6 -0
- package/dist/ui/vendor/three.module.min.js +6 -0
- package/dist/ui/viewer/ambient.js +39 -0
- package/dist/ui/viewer/api.js +93 -0
- package/dist/ui/viewer/chrome.js +36 -0
- package/dist/ui/viewer/edges.js +33 -0
- package/dist/ui/viewer/index.html +32 -0
- package/dist/ui/viewer/inspector.js +23 -0
- package/dist/ui/viewer/lenses/activity.js +24 -0
- package/dist/ui/viewer/lenses/community.js +5 -0
- package/dist/ui/viewer/lenses/edges.js +4 -0
- package/dist/ui/viewer/lenses/impact.js +6 -0
- package/dist/ui/viewer/lenses/search.js +69 -0
- package/dist/ui/viewer/lod.js +100 -0
- package/dist/ui/viewer/main.js +92 -0
- package/dist/ui/viewer/picking.js +45 -0
- package/dist/ui/viewer/scene.js +85 -0
- package/dist/ui/viewer/skins/default-skin.js +15 -0
- package/dist/ui/viewer/skins/loader.js +44 -0
- package/dist/ui/viewer/skins/manifest-schema.js +30 -0
- package/dist/ui/viewer/state.js +44 -0
- package/dist/ui/viewer/theme.js +23 -0
- package/dist/ui/viewer/universe.js +151 -0
- package/dist/ui/viewer/viewer.css +85 -0
- package/dist/util/safeRegex.d.ts.map +1 -1
- package/dist/util/safeRegex.js +221 -68
- package/dist/util/safeRegex.js.map +1 -1
- package/dist/viewer/legacy-graph.d.ts +40 -0
- package/dist/viewer/legacy-graph.d.ts.map +1 -0
- package/dist/viewer/legacy-graph.js +152 -0
- package/dist/viewer/legacy-graph.js.map +1 -0
- package/dist/viewer/routes.d.ts +10 -0
- package/dist/viewer/routes.d.ts.map +1 -0
- package/dist/viewer/routes.js +221 -0
- package/dist/viewer/routes.js.map +1 -0
- package/dist/viewer/service.d.ts +44 -0
- package/dist/viewer/service.d.ts.map +1 -0
- package/dist/viewer/service.js +160 -0
- package/dist/viewer/service.js.map +1 -0
- package/dist/viewer/types.d.ts +63 -0
- package/dist/viewer/types.d.ts.map +1 -0
- package/dist/viewer/types.js +2 -0
- package/dist/viewer/types.js.map +1 -0
- package/dist/viewer/viewer-config.d.ts +12 -0
- package/dist/viewer/viewer-config.d.ts.map +1 -0
- package/dist/viewer/viewer-config.js +36 -0
- package/dist/viewer/viewer-config.js.map +1 -0
- package/package.json +18 -9
- package/templates/SDL.md +19 -0
- package/templates/claude-code.json +8 -43
- package/dist/ui/graph.css +0 -108
- package/dist/ui/graph.d.ts +0 -2
- package/dist/ui/graph.d.ts.map +0 -1
- package/dist/ui/graph.html +0 -52
- package/dist/ui/graph.js +0 -259
- package/dist/ui/graph.js.map +0 -1
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {
|
|
2
|
+
MathUtils,
|
|
3
|
+
Quaternion,
|
|
4
|
+
Vector3
|
|
5
|
+
} from 'three';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* @module CameraUtils
|
|
9
|
+
* @three_import import * as CameraUtils from 'three/addons/utils/CameraUtils.js';
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const _va = /*@__PURE__*/ new Vector3(), // from pe to pa
|
|
13
|
+
_vb = /*@__PURE__*/ new Vector3(), // from pe to pb
|
|
14
|
+
_vc = /*@__PURE__*/ new Vector3(), // from pe to pc
|
|
15
|
+
_vr = /*@__PURE__*/ new Vector3(), // right axis of screen
|
|
16
|
+
_vu = /*@__PURE__*/ new Vector3(), // up axis of screen
|
|
17
|
+
_vn = /*@__PURE__*/ new Vector3(), // normal vector of screen
|
|
18
|
+
_vec = /*@__PURE__*/ new Vector3(), // temporary vector
|
|
19
|
+
_quat = /*@__PURE__*/ new Quaternion(); // temporary quaternion
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Set projection matrix and the orientation of a perspective camera
|
|
24
|
+
* to exactly frame the corners of an arbitrary rectangle.
|
|
25
|
+
* NOTE: This function ignores the standard parameters;
|
|
26
|
+
* do not call `updateProjectionMatrix()` after this.
|
|
27
|
+
*
|
|
28
|
+
* @param {PerspectiveCamera} camera - The camera.
|
|
29
|
+
* @param {Vector3} bottomLeftCorner - The bottom-left corner point.
|
|
30
|
+
* @param {Vector3} bottomRightCorner - The bottom-right corner point.
|
|
31
|
+
* @param {Vector3} topLeftCorner - The top-left corner point.
|
|
32
|
+
* @param {boolean} [estimateViewFrustum=false] - If set to `true`, the function tries to estimate the camera's FOV.
|
|
33
|
+
*/
|
|
34
|
+
function frameCorners( camera, bottomLeftCorner, bottomRightCorner, topLeftCorner, estimateViewFrustum = false ) {
|
|
35
|
+
|
|
36
|
+
const pa = bottomLeftCorner, pb = bottomRightCorner, pc = topLeftCorner;
|
|
37
|
+
const pe = camera.position; // eye position
|
|
38
|
+
const n = camera.near; // distance of near clipping plane
|
|
39
|
+
const f = camera.far; //distance of far clipping plane
|
|
40
|
+
|
|
41
|
+
_vr.copy( pb ).sub( pa ).normalize();
|
|
42
|
+
_vu.copy( pc ).sub( pa ).normalize();
|
|
43
|
+
_vn.crossVectors( _vr, _vu ).normalize();
|
|
44
|
+
|
|
45
|
+
_va.copy( pa ).sub( pe ); // from pe to pa
|
|
46
|
+
_vb.copy( pb ).sub( pe ); // from pe to pb
|
|
47
|
+
_vc.copy( pc ).sub( pe ); // from pe to pc
|
|
48
|
+
|
|
49
|
+
const d = - _va.dot( _vn ); // distance from eye to screen
|
|
50
|
+
const l = _vr.dot( _va ) * n / d; // distance to left screen edge
|
|
51
|
+
const r = _vr.dot( _vb ) * n / d; // distance to right screen edge
|
|
52
|
+
const b = _vu.dot( _va ) * n / d; // distance to bottom screen edge
|
|
53
|
+
const t = _vu.dot( _vc ) * n / d; // distance to top screen edge
|
|
54
|
+
|
|
55
|
+
// Set the camera rotation to match the focal plane to the corners' plane
|
|
56
|
+
_quat.setFromUnitVectors( _vec.set( 0, 1, 0 ), _vu );
|
|
57
|
+
camera.quaternion.setFromUnitVectors( _vec.set( 0, 0, 1 ).applyQuaternion( _quat ), _vn ).multiply( _quat );
|
|
58
|
+
|
|
59
|
+
// Set the off-axis projection matrix to match the corners
|
|
60
|
+
camera.projectionMatrix.set( 2.0 * n / ( r - l ), 0.0,
|
|
61
|
+
( r + l ) / ( r - l ), 0.0, 0.0,
|
|
62
|
+
2.0 * n / ( t - b ),
|
|
63
|
+
( t + b ) / ( t - b ), 0.0, 0.0, 0.0,
|
|
64
|
+
( f + n ) / ( n - f ),
|
|
65
|
+
2.0 * f * n / ( n - f ), 0.0, 0.0, - 1.0, 0.0 );
|
|
66
|
+
camera.projectionMatrixInverse.copy( camera.projectionMatrix ).invert();
|
|
67
|
+
|
|
68
|
+
// FoV estimation to fix frustum culling
|
|
69
|
+
if ( estimateViewFrustum ) {
|
|
70
|
+
|
|
71
|
+
// Set fieldOfView to a conservative estimate
|
|
72
|
+
// to make frustum tall/wide enough to encompass it
|
|
73
|
+
camera.fov =
|
|
74
|
+
MathUtils.RAD2DEG / Math.min( 1.0, camera.aspect ) *
|
|
75
|
+
Math.atan( ( _vec.copy( pb ).sub( pa ).length() +
|
|
76
|
+
( _vec.copy( pc ).sub( pa ).length() ) ) / _va.length() );
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export { frameCorners };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { MathUtils, SRGBColorSpace } from 'three';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @module ColorUtils
|
|
5
|
+
* @three_import import * as ColorUtils from 'three/addons/utils/ColorUtils.js';
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Sets the given color from a color temperature in Kelvin.
|
|
10
|
+
*
|
|
11
|
+
* Converts a correlated color temperature (CTT) to an approximate sRGB color
|
|
12
|
+
* using Tanner Helland's algorithm. Useful for physically-based lighting
|
|
13
|
+
* setups — e.g. candle flame (~1900K), tungsten bulb (~3200K), daylight
|
|
14
|
+
* (~6500K), or clear blue sky (~10000K). Values outside [1000, 40000] are
|
|
15
|
+
* clamped.
|
|
16
|
+
*
|
|
17
|
+
* Reference: https://tannerhelland.com/2012/09/18/convert-temperature-rgb-algorithm-code.html
|
|
18
|
+
*
|
|
19
|
+
* @param {Color} color - The color to set.
|
|
20
|
+
* @param {number} kelvin - Color temperature in Kelvin. Clamped to [1000, 40000].
|
|
21
|
+
* @return {Color} The updated color.
|
|
22
|
+
*/
|
|
23
|
+
function setKelvin( color, kelvin ) {
|
|
24
|
+
|
|
25
|
+
// Algorithm by Tanner Helland (2012). Inputs are divided by 100.
|
|
26
|
+
const temp = MathUtils.clamp( kelvin, 1000, 40000 ) / 100;
|
|
27
|
+
|
|
28
|
+
let r, g, b;
|
|
29
|
+
|
|
30
|
+
// Red channel
|
|
31
|
+
if ( temp <= 66 ) {
|
|
32
|
+
|
|
33
|
+
r = 255;
|
|
34
|
+
|
|
35
|
+
} else {
|
|
36
|
+
|
|
37
|
+
r = 329.698727446 * Math.pow( temp - 60, - 0.1332047592 );
|
|
38
|
+
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Green channel
|
|
42
|
+
if ( temp <= 66 ) {
|
|
43
|
+
|
|
44
|
+
g = 99.4708025861 * Math.log( temp ) - 161.1195681661;
|
|
45
|
+
|
|
46
|
+
} else {
|
|
47
|
+
|
|
48
|
+
g = 288.1221695283 * Math.pow( temp - 60, - 0.0755148492 );
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Blue channel
|
|
53
|
+
if ( temp >= 66 ) {
|
|
54
|
+
|
|
55
|
+
b = 255;
|
|
56
|
+
|
|
57
|
+
} else if ( temp <= 19 ) {
|
|
58
|
+
|
|
59
|
+
b = 0;
|
|
60
|
+
|
|
61
|
+
} else {
|
|
62
|
+
|
|
63
|
+
b = 138.5177312231 * Math.log( temp - 10 ) - 305.0447927307;
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return color.setRGB(
|
|
68
|
+
MathUtils.clamp( r, 0, 255 ) / 255,
|
|
69
|
+
MathUtils.clamp( g, 0, 255 ) / 255,
|
|
70
|
+
MathUtils.clamp( b, 0, 255 ) / 255,
|
|
71
|
+
SRGBColorSpace
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export { setKelvin };
|
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BufferAttribute,
|
|
3
|
+
Matrix3,
|
|
4
|
+
Matrix4,
|
|
5
|
+
Vector3
|
|
6
|
+
} from 'three';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @module GeometryCompressionUtils
|
|
10
|
+
* @three_import import * as GeometryCompressionUtils from 'three/addons/utils/GeometryCompressionUtils.js';
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// Octahedron and Quantization encodings based on work by: https://github.com/tsherif/mesh-quantization-example
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Compressed the given geometry's `normal` attribute by the selected encode method.
|
|
17
|
+
*
|
|
18
|
+
* @param {BufferGeometry} geometry - The geometry whose normals should be compressed.
|
|
19
|
+
* @param {('DEFAULT'|'OCT1Byte'|'OCT2Byte'|'ANGLES')} encodeMethod - The compression method.
|
|
20
|
+
*/
|
|
21
|
+
function compressNormals( geometry, encodeMethod ) {
|
|
22
|
+
|
|
23
|
+
const normal = geometry.attributes.normal;
|
|
24
|
+
|
|
25
|
+
if ( ! normal ) {
|
|
26
|
+
|
|
27
|
+
console.error( 'THREE.GeometryCompressionUtils.compressNormals(): Geometry must contain normal attribute.' );
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if ( normal.isPacked ) return;
|
|
32
|
+
|
|
33
|
+
if ( normal.itemSize != 3 ) {
|
|
34
|
+
|
|
35
|
+
console.error( 'THREE.GeometryCompressionUtils.compressNormals(): normal.itemSize is not 3, which cannot be encoded.' );
|
|
36
|
+
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const array = normal.array;
|
|
40
|
+
const count = normal.count;
|
|
41
|
+
|
|
42
|
+
let result;
|
|
43
|
+
if ( encodeMethod == 'DEFAULT' ) {
|
|
44
|
+
|
|
45
|
+
// TODO: Add 1 byte to the result, making the encoded length to be 4 bytes.
|
|
46
|
+
result = new Uint8Array( count * 3 );
|
|
47
|
+
|
|
48
|
+
for ( let idx = 0; idx < array.length; idx += 3 ) {
|
|
49
|
+
|
|
50
|
+
const encoded = defaultEncode( array[ idx ], array[ idx + 1 ], array[ idx + 2 ], 1 );
|
|
51
|
+
|
|
52
|
+
result[ idx + 0 ] = encoded[ 0 ];
|
|
53
|
+
result[ idx + 1 ] = encoded[ 1 ];
|
|
54
|
+
result[ idx + 2 ] = encoded[ 2 ];
|
|
55
|
+
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
geometry.setAttribute( 'normal', new BufferAttribute( result, 3, true ) );
|
|
59
|
+
geometry.attributes.normal.bytes = result.length * 1;
|
|
60
|
+
|
|
61
|
+
} else if ( encodeMethod == 'OCT1Byte' ) {
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
// It is not recommended to use 1-byte octahedron normals encoding unless you want to extremely reduce the memory usage
|
|
65
|
+
// As it makes vertex data not aligned to a 4 byte boundary which may harm some WebGL implementations and sometimes the normal distortion is visible
|
|
66
|
+
// Please refer to @zeux 's comments in https://github.com/mrdoob/three.js/pull/18208
|
|
67
|
+
|
|
68
|
+
result = new Int8Array( count * 2 );
|
|
69
|
+
|
|
70
|
+
for ( let idx = 0; idx < array.length; idx += 3 ) {
|
|
71
|
+
|
|
72
|
+
const encoded = octEncodeBest( array[ idx ], array[ idx + 1 ], array[ idx + 2 ], 1 );
|
|
73
|
+
|
|
74
|
+
result[ idx / 3 * 2 + 0 ] = encoded[ 0 ];
|
|
75
|
+
result[ idx / 3 * 2 + 1 ] = encoded[ 1 ];
|
|
76
|
+
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
geometry.setAttribute( 'normal', new BufferAttribute( result, 2, true ) );
|
|
80
|
+
geometry.attributes.normal.bytes = result.length * 1;
|
|
81
|
+
|
|
82
|
+
} else if ( encodeMethod == 'OCT2Byte' ) {
|
|
83
|
+
|
|
84
|
+
result = new Int16Array( count * 2 );
|
|
85
|
+
|
|
86
|
+
for ( let idx = 0; idx < array.length; idx += 3 ) {
|
|
87
|
+
|
|
88
|
+
const encoded = octEncodeBest( array[ idx ], array[ idx + 1 ], array[ idx + 2 ], 2 );
|
|
89
|
+
|
|
90
|
+
result[ idx / 3 * 2 + 0 ] = encoded[ 0 ];
|
|
91
|
+
result[ idx / 3 * 2 + 1 ] = encoded[ 1 ];
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
geometry.setAttribute( 'normal', new BufferAttribute( result, 2, true ) );
|
|
96
|
+
geometry.attributes.normal.bytes = result.length * 2;
|
|
97
|
+
|
|
98
|
+
} else if ( encodeMethod == 'ANGLES' ) {
|
|
99
|
+
|
|
100
|
+
result = new Uint16Array( count * 2 );
|
|
101
|
+
|
|
102
|
+
for ( let idx = 0; idx < array.length; idx += 3 ) {
|
|
103
|
+
|
|
104
|
+
const encoded = anglesEncode( array[ idx ], array[ idx + 1 ], array[ idx + 2 ] );
|
|
105
|
+
|
|
106
|
+
result[ idx / 3 * 2 + 0 ] = encoded[ 0 ];
|
|
107
|
+
result[ idx / 3 * 2 + 1 ] = encoded[ 1 ];
|
|
108
|
+
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
geometry.setAttribute( 'normal', new BufferAttribute( result, 2, true ) );
|
|
112
|
+
geometry.attributes.normal.bytes = result.length * 2;
|
|
113
|
+
|
|
114
|
+
} else {
|
|
115
|
+
|
|
116
|
+
console.error( 'Unrecognized encoding method, should be `DEFAULT` or `ANGLES` or `OCT`. ' );
|
|
117
|
+
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
geometry.attributes.normal.needsUpdate = true;
|
|
121
|
+
geometry.attributes.normal.isPacked = true;
|
|
122
|
+
geometry.attributes.normal.packingMethod = encodeMethod;
|
|
123
|
+
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Compressed the given geometry's `position` attribute.
|
|
128
|
+
*
|
|
129
|
+
* @param {BufferGeometry} geometry - The geometry whose position values should be compressed.
|
|
130
|
+
*/
|
|
131
|
+
function compressPositions( geometry ) {
|
|
132
|
+
|
|
133
|
+
const position = geometry.attributes.position;
|
|
134
|
+
|
|
135
|
+
if ( ! position ) {
|
|
136
|
+
|
|
137
|
+
console.error( 'THREE.GeometryCompressionUtils.compressPositions(): Geometry must contain position attribute.' );
|
|
138
|
+
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if ( position.isPacked ) return;
|
|
142
|
+
|
|
143
|
+
if ( position.itemSize != 3 ) {
|
|
144
|
+
|
|
145
|
+
console.error( 'THREE.GeometryCompressionUtils.compressPositions(): position.itemSize is not 3, which cannot be packed.' );
|
|
146
|
+
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const array = position.array;
|
|
150
|
+
const encodingBytes = 2;
|
|
151
|
+
|
|
152
|
+
const result = quantizedEncode( array, encodingBytes );
|
|
153
|
+
|
|
154
|
+
const quantized = result.quantized;
|
|
155
|
+
|
|
156
|
+
// IMPORTANT: calculate original geometry bounding info first, before updating packed positions
|
|
157
|
+
if ( geometry.boundingBox == null ) geometry.computeBoundingBox();
|
|
158
|
+
if ( geometry.boundingSphere == null ) geometry.computeBoundingSphere();
|
|
159
|
+
|
|
160
|
+
geometry.setAttribute( 'position', new BufferAttribute( quantized, 3 ) );
|
|
161
|
+
geometry.attributes.position.isPacked = true;
|
|
162
|
+
geometry.attributes.position.needsUpdate = true;
|
|
163
|
+
geometry.attributes.position.bytes = quantized.length * encodingBytes;
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Compressed the given geometry's `uv` attribute.
|
|
169
|
+
*
|
|
170
|
+
* @param {BufferGeometry} geometry - The geometry whose texture coordinates should be compressed.
|
|
171
|
+
*/
|
|
172
|
+
function compressUvs( geometry ) {
|
|
173
|
+
|
|
174
|
+
const uvs = geometry.attributes.uv;
|
|
175
|
+
|
|
176
|
+
if ( ! uvs ) {
|
|
177
|
+
|
|
178
|
+
console.error( 'THREE.GeometryCompressionUtils.compressUvs(): Geometry must contain uv attribute.' );
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if ( uvs.isPacked ) return;
|
|
183
|
+
|
|
184
|
+
const range = { min: Infinity, max: - Infinity };
|
|
185
|
+
|
|
186
|
+
const array = uvs.array;
|
|
187
|
+
|
|
188
|
+
for ( let i = 0; i < array.length; i ++ ) {
|
|
189
|
+
|
|
190
|
+
range.min = Math.min( range.min, array[ i ] );
|
|
191
|
+
range.max = Math.max( range.max, array[ i ] );
|
|
192
|
+
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
let result;
|
|
196
|
+
|
|
197
|
+
if ( range.min >= - 1.0 && range.max <= 1.0 ) {
|
|
198
|
+
|
|
199
|
+
// use default encoding method
|
|
200
|
+
result = new Uint16Array( array.length );
|
|
201
|
+
|
|
202
|
+
for ( let i = 0; i < array.length; i += 2 ) {
|
|
203
|
+
|
|
204
|
+
const encoded = defaultEncode( array[ i ], array[ i + 1 ], 0, 2 );
|
|
205
|
+
|
|
206
|
+
result[ i ] = encoded[ 0 ];
|
|
207
|
+
result[ i + 1 ] = encoded[ 1 ];
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
geometry.setAttribute( 'uv', new BufferAttribute( result, 2, true ) );
|
|
212
|
+
geometry.attributes.uv.isPacked = true;
|
|
213
|
+
geometry.attributes.uv.needsUpdate = true;
|
|
214
|
+
geometry.attributes.uv.bytes = result.length * 2;
|
|
215
|
+
|
|
216
|
+
} else {
|
|
217
|
+
|
|
218
|
+
// use quantized encoding method
|
|
219
|
+
result = quantizedEncodeUV( array, 2 );
|
|
220
|
+
|
|
221
|
+
geometry.setAttribute( 'uv', new BufferAttribute( result.quantized, 2 ) );
|
|
222
|
+
geometry.attributes.uv.isPacked = true;
|
|
223
|
+
geometry.attributes.uv.needsUpdate = true;
|
|
224
|
+
geometry.attributes.uv.bytes = result.quantized.length * 2;
|
|
225
|
+
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
// Encoding functions
|
|
232
|
+
|
|
233
|
+
function defaultEncode( x, y, z, bytes ) {
|
|
234
|
+
|
|
235
|
+
if ( bytes == 1 ) {
|
|
236
|
+
|
|
237
|
+
const tmpx = Math.round( ( x + 1 ) * 0.5 * 255 );
|
|
238
|
+
const tmpy = Math.round( ( y + 1 ) * 0.5 * 255 );
|
|
239
|
+
const tmpz = Math.round( ( z + 1 ) * 0.5 * 255 );
|
|
240
|
+
return new Uint8Array( [ tmpx, tmpy, tmpz ] );
|
|
241
|
+
|
|
242
|
+
} else if ( bytes == 2 ) {
|
|
243
|
+
|
|
244
|
+
const tmpx = Math.round( ( x + 1 ) * 0.5 * 65535 );
|
|
245
|
+
const tmpy = Math.round( ( y + 1 ) * 0.5 * 65535 );
|
|
246
|
+
const tmpz = Math.round( ( z + 1 ) * 0.5 * 65535 );
|
|
247
|
+
return new Uint16Array( [ tmpx, tmpy, tmpz ] );
|
|
248
|
+
|
|
249
|
+
} else {
|
|
250
|
+
|
|
251
|
+
console.error( 'number of bytes must be 1 or 2' );
|
|
252
|
+
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// for `Angles` encoding
|
|
258
|
+
function anglesEncode( x, y, z ) {
|
|
259
|
+
|
|
260
|
+
const normal0 = parseInt( 0.5 * ( 1.0 + Math.atan2( y, x ) / Math.PI ) * 65535 );
|
|
261
|
+
const normal1 = parseInt( 0.5 * ( 1.0 + z ) * 65535 );
|
|
262
|
+
return new Uint16Array( [ normal0, normal1 ] );
|
|
263
|
+
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// for `Octahedron` encoding
|
|
267
|
+
function octEncodeBest( x, y, z, bytes ) {
|
|
268
|
+
|
|
269
|
+
let oct, dec, best, currentCos, bestCos;
|
|
270
|
+
|
|
271
|
+
// Test various combinations of ceil and floor
|
|
272
|
+
// to minimize rounding errors
|
|
273
|
+
best = oct = octEncodeVec3( x, y, z, 'floor', 'floor' );
|
|
274
|
+
dec = octDecodeVec2( oct );
|
|
275
|
+
bestCos = dot( x, y, z, dec );
|
|
276
|
+
|
|
277
|
+
oct = octEncodeVec3( x, y, z, 'ceil', 'floor' );
|
|
278
|
+
dec = octDecodeVec2( oct );
|
|
279
|
+
currentCos = dot( x, y, z, dec );
|
|
280
|
+
|
|
281
|
+
if ( currentCos > bestCos ) {
|
|
282
|
+
|
|
283
|
+
best = oct;
|
|
284
|
+
bestCos = currentCos;
|
|
285
|
+
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
oct = octEncodeVec3( x, y, z, 'floor', 'ceil' );
|
|
289
|
+
dec = octDecodeVec2( oct );
|
|
290
|
+
currentCos = dot( x, y, z, dec );
|
|
291
|
+
|
|
292
|
+
if ( currentCos > bestCos ) {
|
|
293
|
+
|
|
294
|
+
best = oct;
|
|
295
|
+
bestCos = currentCos;
|
|
296
|
+
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
oct = octEncodeVec3( x, y, z, 'ceil', 'ceil' );
|
|
300
|
+
dec = octDecodeVec2( oct );
|
|
301
|
+
currentCos = dot( x, y, z, dec );
|
|
302
|
+
|
|
303
|
+
if ( currentCos > bestCos ) {
|
|
304
|
+
|
|
305
|
+
best = oct;
|
|
306
|
+
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return best;
|
|
310
|
+
|
|
311
|
+
function octEncodeVec3( x0, y0, z0, xfunc, yfunc ) {
|
|
312
|
+
|
|
313
|
+
let x = x0 / ( Math.abs( x0 ) + Math.abs( y0 ) + Math.abs( z0 ) );
|
|
314
|
+
let y = y0 / ( Math.abs( x0 ) + Math.abs( y0 ) + Math.abs( z0 ) );
|
|
315
|
+
|
|
316
|
+
if ( z < 0 ) {
|
|
317
|
+
|
|
318
|
+
const tempx = ( 1 - Math.abs( y ) ) * ( x >= 0 ? 1 : - 1 );
|
|
319
|
+
const tempy = ( 1 - Math.abs( x ) ) * ( y >= 0 ? 1 : - 1 );
|
|
320
|
+
|
|
321
|
+
x = tempx;
|
|
322
|
+
y = tempy;
|
|
323
|
+
|
|
324
|
+
let diff = 1 - Math.abs( x ) - Math.abs( y );
|
|
325
|
+
if ( diff > 0 ) {
|
|
326
|
+
|
|
327
|
+
diff += 0.001;
|
|
328
|
+
x += x > 0 ? diff / 2 : - diff / 2;
|
|
329
|
+
y += y > 0 ? diff / 2 : - diff / 2;
|
|
330
|
+
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if ( bytes == 1 ) {
|
|
336
|
+
|
|
337
|
+
return new Int8Array( [
|
|
338
|
+
Math[ xfunc ]( x * 127.5 + ( x < 0 ? 1 : 0 ) ),
|
|
339
|
+
Math[ yfunc ]( y * 127.5 + ( y < 0 ? 1 : 0 ) )
|
|
340
|
+
] );
|
|
341
|
+
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
if ( bytes == 2 ) {
|
|
345
|
+
|
|
346
|
+
return new Int16Array( [
|
|
347
|
+
Math[ xfunc ]( x * 32767.5 + ( x < 0 ? 1 : 0 ) ),
|
|
348
|
+
Math[ yfunc ]( y * 32767.5 + ( y < 0 ? 1 : 0 ) )
|
|
349
|
+
] );
|
|
350
|
+
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
function octDecodeVec2( oct ) {
|
|
357
|
+
|
|
358
|
+
let x = oct[ 0 ];
|
|
359
|
+
let y = oct[ 1 ];
|
|
360
|
+
|
|
361
|
+
if ( bytes == 1 ) {
|
|
362
|
+
|
|
363
|
+
x /= x < 0 ? 127 : 128;
|
|
364
|
+
y /= y < 0 ? 127 : 128;
|
|
365
|
+
|
|
366
|
+
} else if ( bytes == 2 ) {
|
|
367
|
+
|
|
368
|
+
x /= x < 0 ? 32767 : 32768;
|
|
369
|
+
y /= y < 0 ? 32767 : 32768;
|
|
370
|
+
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
const z = 1 - Math.abs( x ) - Math.abs( y );
|
|
375
|
+
|
|
376
|
+
if ( z < 0 ) {
|
|
377
|
+
|
|
378
|
+
const tmpx = x;
|
|
379
|
+
x = ( 1 - Math.abs( y ) ) * ( x >= 0 ? 1 : - 1 );
|
|
380
|
+
y = ( 1 - Math.abs( tmpx ) ) * ( y >= 0 ? 1 : - 1 );
|
|
381
|
+
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
const length = Math.sqrt( x * x + y * y + z * z );
|
|
385
|
+
|
|
386
|
+
return [
|
|
387
|
+
x / length,
|
|
388
|
+
y / length,
|
|
389
|
+
z / length
|
|
390
|
+
];
|
|
391
|
+
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
function dot( x, y, z, vec3 ) {
|
|
395
|
+
|
|
396
|
+
return x * vec3[ 0 ] + y * vec3[ 1 ] + z * vec3[ 2 ];
|
|
397
|
+
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
function quantizedEncode( array, bytes ) {
|
|
403
|
+
|
|
404
|
+
let quantized, segments;
|
|
405
|
+
|
|
406
|
+
if ( bytes == 1 ) {
|
|
407
|
+
|
|
408
|
+
quantized = new Uint8Array( array.length );
|
|
409
|
+
segments = 255;
|
|
410
|
+
|
|
411
|
+
} else if ( bytes == 2 ) {
|
|
412
|
+
|
|
413
|
+
quantized = new Uint16Array( array.length );
|
|
414
|
+
segments = 65535;
|
|
415
|
+
|
|
416
|
+
} else {
|
|
417
|
+
|
|
418
|
+
console.error( 'number of bytes error! ' );
|
|
419
|
+
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const decodeMat = new Matrix4();
|
|
423
|
+
|
|
424
|
+
const min = new Float32Array( 3 );
|
|
425
|
+
const max = new Float32Array( 3 );
|
|
426
|
+
|
|
427
|
+
min[ 0 ] = min[ 1 ] = min[ 2 ] = Number.MAX_VALUE;
|
|
428
|
+
max[ 0 ] = max[ 1 ] = max[ 2 ] = - Number.MAX_VALUE;
|
|
429
|
+
|
|
430
|
+
for ( let i = 0; i < array.length; i += 3 ) {
|
|
431
|
+
|
|
432
|
+
min[ 0 ] = Math.min( min[ 0 ], array[ i + 0 ] );
|
|
433
|
+
min[ 1 ] = Math.min( min[ 1 ], array[ i + 1 ] );
|
|
434
|
+
min[ 2 ] = Math.min( min[ 2 ], array[ i + 2 ] );
|
|
435
|
+
max[ 0 ] = Math.max( max[ 0 ], array[ i + 0 ] );
|
|
436
|
+
max[ 1 ] = Math.max( max[ 1 ], array[ i + 1 ] );
|
|
437
|
+
max[ 2 ] = Math.max( max[ 2 ], array[ i + 2 ] );
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
decodeMat.scale( new Vector3(
|
|
442
|
+
( max[ 0 ] - min[ 0 ] ) / segments,
|
|
443
|
+
( max[ 1 ] - min[ 1 ] ) / segments,
|
|
444
|
+
( max[ 2 ] - min[ 2 ] ) / segments
|
|
445
|
+
) );
|
|
446
|
+
|
|
447
|
+
decodeMat.elements[ 12 ] = min[ 0 ];
|
|
448
|
+
decodeMat.elements[ 13 ] = min[ 1 ];
|
|
449
|
+
decodeMat.elements[ 14 ] = min[ 2 ];
|
|
450
|
+
|
|
451
|
+
decodeMat.transpose();
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
const multiplier = new Float32Array( [
|
|
455
|
+
max[ 0 ] !== min[ 0 ] ? segments / ( max[ 0 ] - min[ 0 ] ) : 0,
|
|
456
|
+
max[ 1 ] !== min[ 1 ] ? segments / ( max[ 1 ] - min[ 1 ] ) : 0,
|
|
457
|
+
max[ 2 ] !== min[ 2 ] ? segments / ( max[ 2 ] - min[ 2 ] ) : 0
|
|
458
|
+
] );
|
|
459
|
+
|
|
460
|
+
for ( let i = 0; i < array.length; i += 3 ) {
|
|
461
|
+
|
|
462
|
+
quantized[ i + 0 ] = Math.floor( ( array[ i + 0 ] - min[ 0 ] ) * multiplier[ 0 ] );
|
|
463
|
+
quantized[ i + 1 ] = Math.floor( ( array[ i + 1 ] - min[ 1 ] ) * multiplier[ 1 ] );
|
|
464
|
+
quantized[ i + 2 ] = Math.floor( ( array[ i + 2 ] - min[ 2 ] ) * multiplier[ 2 ] );
|
|
465
|
+
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
return {
|
|
469
|
+
quantized: quantized,
|
|
470
|
+
decodeMat: decodeMat
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
function quantizedEncodeUV( array, bytes ) {
|
|
476
|
+
|
|
477
|
+
let quantized, segments;
|
|
478
|
+
|
|
479
|
+
if ( bytes == 1 ) {
|
|
480
|
+
|
|
481
|
+
quantized = new Uint8Array( array.length );
|
|
482
|
+
segments = 255;
|
|
483
|
+
|
|
484
|
+
} else if ( bytes == 2 ) {
|
|
485
|
+
|
|
486
|
+
quantized = new Uint16Array( array.length );
|
|
487
|
+
segments = 65535;
|
|
488
|
+
|
|
489
|
+
} else {
|
|
490
|
+
|
|
491
|
+
console.error( 'number of bytes error! ' );
|
|
492
|
+
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
const decodeMat = new Matrix3();
|
|
496
|
+
|
|
497
|
+
const min = new Float32Array( 2 );
|
|
498
|
+
const max = new Float32Array( 2 );
|
|
499
|
+
|
|
500
|
+
min[ 0 ] = min[ 1 ] = Number.MAX_VALUE;
|
|
501
|
+
max[ 0 ] = max[ 1 ] = - Number.MAX_VALUE;
|
|
502
|
+
|
|
503
|
+
for ( let i = 0; i < array.length; i += 2 ) {
|
|
504
|
+
|
|
505
|
+
min[ 0 ] = Math.min( min[ 0 ], array[ i + 0 ] );
|
|
506
|
+
min[ 1 ] = Math.min( min[ 1 ], array[ i + 1 ] );
|
|
507
|
+
max[ 0 ] = Math.max( max[ 0 ], array[ i + 0 ] );
|
|
508
|
+
max[ 1 ] = Math.max( max[ 1 ], array[ i + 1 ] );
|
|
509
|
+
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
decodeMat.makeScale(
|
|
513
|
+
( max[ 0 ] - min[ 0 ] ) / segments,
|
|
514
|
+
( max[ 1 ] - min[ 1 ] ) / segments
|
|
515
|
+
);
|
|
516
|
+
|
|
517
|
+
decodeMat.elements[ 6 ] = min[ 0 ];
|
|
518
|
+
decodeMat.elements[ 7 ] = min[ 1 ];
|
|
519
|
+
|
|
520
|
+
decodeMat.transpose();
|
|
521
|
+
|
|
522
|
+
const multiplier = new Float32Array( [
|
|
523
|
+
max[ 0 ] !== min[ 0 ] ? segments / ( max[ 0 ] - min[ 0 ] ) : 0,
|
|
524
|
+
max[ 1 ] !== min[ 1 ] ? segments / ( max[ 1 ] - min[ 1 ] ) : 0
|
|
525
|
+
] );
|
|
526
|
+
|
|
527
|
+
for ( let i = 0; i < array.length; i += 2 ) {
|
|
528
|
+
|
|
529
|
+
quantized[ i + 0 ] = Math.floor( ( array[ i + 0 ] - min[ 0 ] ) * multiplier[ 0 ] );
|
|
530
|
+
quantized[ i + 1 ] = Math.floor( ( array[ i + 1 ] - min[ 1 ] ) * multiplier[ 1 ] );
|
|
531
|
+
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
return {
|
|
535
|
+
quantized: quantized,
|
|
536
|
+
decodeMat: decodeMat
|
|
537
|
+
};
|
|
538
|
+
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
|
|
543
|
+
export {
|
|
544
|
+
compressNormals,
|
|
545
|
+
compressPositions,
|
|
546
|
+
compressUvs,
|
|
547
|
+
};
|