three-cad-viewer 4.2.0 → 4.3.0
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/dist/core/studio-manager.d.ts +0 -1
- package/dist/core/types.d.ts +1 -22
- package/dist/index.d.ts +1 -1
- package/dist/rendering/texture-cache.d.ts +8 -50
- package/dist/scene/nestedgroup.d.ts +1 -2
- package/dist/three-cad-viewer.esm.js +18 -641
- package/dist/three-cad-viewer.esm.js.map +1 -1
- package/dist/three-cad-viewer.esm.min.js +3 -3
- package/dist/three-cad-viewer.js +18 -641
- package/dist/three-cad-viewer.min.js +3 -3
- package/package.json +1 -1
- package/src/_version.ts +1 -1
- package/src/core/studio-manager.ts +4 -34
- package/src/core/types.ts +1 -27
- package/src/index.ts +0 -1
- package/src/rendering/material-factory.ts +2 -0
- package/src/rendering/material-presets.ts +0 -14
- package/src/rendering/texture-cache.ts +11 -712
- package/src/scene/nestedgroup.ts +0 -7
package/dist/core/types.d.ts
CHANGED
|
@@ -402,8 +402,7 @@ export type StateKey = keyof ViewerStateShape;
|
|
|
402
402
|
* which the shader skips at near-zero cost.
|
|
403
403
|
*
|
|
404
404
|
* This is a data-format interface (describes JSON input), not a Three.js material.
|
|
405
|
-
* Texture string fields
|
|
406
|
-
* a data URI, or a URL resolved against the HTML page.
|
|
405
|
+
* Texture string fields are either a data URI or a URL resolved against the HTML page.
|
|
407
406
|
*/
|
|
408
407
|
export interface MaterialAppearance {
|
|
409
408
|
/** Display name */
|
|
@@ -516,23 +515,6 @@ export interface MaterialXMaterial {
|
|
|
516
515
|
* Detected by the presence of the `properties` key.
|
|
517
516
|
*/
|
|
518
517
|
export declare function isMaterialXMaterial(m: unknown): m is MaterialXMaterial;
|
|
519
|
-
/**
|
|
520
|
-
* Entry in the root-level `textures` table.
|
|
521
|
-
*
|
|
522
|
-
* Each entry is either embedded (base64-encoded image data) or a URL reference
|
|
523
|
-
* loaded on demand. At least one of `data`+`format` or `url` must be provided.
|
|
524
|
-
* An empty TextureEntry is invalid and will be ignored at runtime.
|
|
525
|
-
* Multiple builtin preset texture fields can reference the same key for
|
|
526
|
-
* deduplication. threejs-materials carry their own textures as inline data URIs.
|
|
527
|
-
*/
|
|
528
|
-
export interface TextureEntry {
|
|
529
|
-
/** Base64-encoded image data (for embedded textures) */
|
|
530
|
-
data?: string;
|
|
531
|
-
/** Image format, e.g., "png", "jpg", "webp" (required when data is provided) */
|
|
532
|
-
format?: string;
|
|
533
|
-
/** URL to load the texture from (for URL-referenced textures) */
|
|
534
|
-
url?: string;
|
|
535
|
-
}
|
|
536
518
|
/**
|
|
537
519
|
* Root-level Studio mode configuration.
|
|
538
520
|
*
|
|
@@ -719,9 +701,6 @@ export interface Shapes {
|
|
|
719
701
|
* - MaterialAppearance: preset with overrides (e.g., { builtin: "acrylic-clear", color: "#55a0e3" })
|
|
720
702
|
*/
|
|
721
703
|
materials?: Record<string, string | MaterialXMaterial | MaterialAppearance> | undefined;
|
|
722
|
-
/** Shared texture table for builtin preset materials (root node).
|
|
723
|
-
* threejs-materials carry their own textures inline. */
|
|
724
|
-
textures?: Record<string, TextureEntry> | undefined;
|
|
725
704
|
}
|
|
726
705
|
/** Callback for DOM events */
|
|
727
706
|
export type DomEventCallback = (event: Event) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type { Texture, Shape, ShapeBinary, ShapeNested, Location, VisibilityValu
|
|
|
32
32
|
export { isShapeBinaryFormat, hasTrianglesPerFace, hasSegmentsPerEdge, } from "./core/types.js";
|
|
33
33
|
export type { DomEventCallback } from "./core/types.js";
|
|
34
34
|
export type { ColoredMaterial } from "./core/types.js";
|
|
35
|
-
export type { MaterialAppearance, MaterialXMaterial,
|
|
35
|
+
export type { MaterialAppearance, MaterialXMaterial, StudioOptions, StudioBackground, StudioModeOptions, StudioEnvironment, StudioToneMapping, StudioTextureMapping, } from "./core/types.js";
|
|
36
36
|
export { isMaterialXMaterial } from "./core/types.js";
|
|
37
37
|
export { isInstancedFormat, decodeInstancedFormat } from "./utils/decode-instances.js";
|
|
38
38
|
export type { SubscribeOptions } from "./core/types.js";
|
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
import * as THREE from "three";
|
|
2
|
-
import type { TextureEntry } from "../core/types.js";
|
|
3
|
-
/** Names of all supported builtin procedural textures */
|
|
4
|
-
declare const BUILTIN_NAMES: readonly ["brushed", "knurled", "sandblasted", "hammered", "checker", "wood-dark", "leather", "fabric-weave"];
|
|
5
2
|
/**
|
|
6
3
|
* Texture fields that carry sRGB color data.
|
|
7
4
|
*
|
|
@@ -19,45 +16,28 @@ declare const SRGB_TEXTURE_ROLES: Set<string>;
|
|
|
19
16
|
* Only TextureCache.dispose() / disposeFull() disposes GPU texture resources.
|
|
20
17
|
*
|
|
21
18
|
* Resolution order for texture reference strings:
|
|
22
|
-
* 1. `
|
|
23
|
-
* 2.
|
|
24
|
-
* 3. `data:` prefix -- treat as data URI, load directly
|
|
25
|
-
* 4. Otherwise -- treat as URL, resolve relative to HTML page
|
|
19
|
+
* 1. `data:` prefix -- treat as data URI, load directly
|
|
20
|
+
* 2. Otherwise -- treat as URL, resolve relative to HTML page
|
|
26
21
|
*
|
|
27
22
|
* Features:
|
|
28
|
-
* - Two-tier caching: user textures (disposed on clear) + builtin textures
|
|
29
|
-
* (persistent, only disposed on viewer teardown)
|
|
30
23
|
* - In-flight promise deduplication (no duplicate loads for the same key)
|
|
31
24
|
* - Correct colorSpace assignment per texture semantic role
|
|
32
25
|
* - GPU resource tracking via gpuTracker
|
|
33
26
|
*/
|
|
34
27
|
declare class TextureCache {
|
|
35
|
-
/**
|
|
28
|
+
/** Textures cache (disposed on clear/dispose, rebuilt per shape data) */
|
|
36
29
|
private _cache;
|
|
37
|
-
/** Built-in procedural textures (persistent, only disposed via disposeFull) */
|
|
38
|
-
private _builtinCache;
|
|
39
30
|
/** In-flight load promises keyed by cache key */
|
|
40
31
|
private _inflight;
|
|
41
|
-
/** Root-level textures table from shape data */
|
|
42
|
-
private _texturesTable;
|
|
43
32
|
/** THREE.TextureLoader instance (created lazily) */
|
|
44
33
|
private _textureLoader;
|
|
45
34
|
/** Whether this cache has been fully disposed */
|
|
46
35
|
private _disposed;
|
|
47
|
-
/**
|
|
48
|
-
* Set or update the root-level textures table.
|
|
49
|
-
*
|
|
50
|
-
* Called when new shape data is loaded. The table maps string keys to
|
|
51
|
-
* TextureEntry objects (embedded base64 data or URL references).
|
|
52
|
-
*
|
|
53
|
-
* @param table - The textures table from root Shapes node, or undefined to clear
|
|
54
|
-
*/
|
|
55
|
-
setTexturesTable(table: Record<string, TextureEntry> | undefined): void;
|
|
56
36
|
/**
|
|
57
37
|
* Resolve a texture reference string and return a cached or newly loaded
|
|
58
38
|
* THREE.Texture with the correct colorSpace set.
|
|
59
39
|
*
|
|
60
|
-
* @param ref - Texture reference string (
|
|
40
|
+
* @param ref - Texture reference string (table key, data URI, or URL)
|
|
61
41
|
* @param textureRole - The texture role name (MaterialAppearance field name or proxy role)
|
|
62
42
|
* (e.g. "baseColorTexture", "normalTexture"). Used to determine colorSpace.
|
|
63
43
|
* @returns The resolved THREE.Texture, or null if the reference is invalid
|
|
@@ -65,36 +45,18 @@ declare class TextureCache {
|
|
|
65
45
|
*/
|
|
66
46
|
get(ref: string, textureRole: string): Promise<THREE.Texture | null>;
|
|
67
47
|
/**
|
|
68
|
-
*
|
|
69
|
-
*/
|
|
70
|
-
isBuiltin(ref: string): boolean;
|
|
71
|
-
/**
|
|
72
|
-
* Dispose user textures (called on viewer.clear() when shape data is replaced).
|
|
48
|
+
* Dispose textures (called on viewer.clear() when shape data is replaced).
|
|
73
49
|
*
|
|
74
|
-
* Disposes all textures in the
|
|
75
|
-
* The builtin procedural texture cache is preserved.
|
|
50
|
+
* Disposes all textures in the cache and clears in-flight promises.
|
|
76
51
|
*/
|
|
77
52
|
dispose(): void;
|
|
78
53
|
/**
|
|
79
|
-
* Dispose all textures
|
|
54
|
+
* Dispose all textures.
|
|
80
55
|
*
|
|
81
56
|
* Called on viewer.dispose() when the viewer is fully torn down.
|
|
82
57
|
* After this call, the TextureCache cannot be used again.
|
|
83
58
|
*/
|
|
84
59
|
disposeFull(): void;
|
|
85
|
-
/**
|
|
86
|
-
* Get or generate a builtin procedural texture.
|
|
87
|
-
*
|
|
88
|
-
* Builtin textures are cached in the persistent `_builtinCache` and survive
|
|
89
|
-
* `dispose()` calls. They are only freed via `disposeFull()`.
|
|
90
|
-
*/
|
|
91
|
-
private _getBuiltin;
|
|
92
|
-
/**
|
|
93
|
-
* Load a texture from the root-level textures table entry.
|
|
94
|
-
*
|
|
95
|
-
* Handles both embedded (base64 data) and URL-referenced entries.
|
|
96
|
-
*/
|
|
97
|
-
private _getFromTable;
|
|
98
60
|
/**
|
|
99
61
|
* Load a texture from a data URI string.
|
|
100
62
|
*/
|
|
@@ -124,10 +86,6 @@ declare class TextureCache {
|
|
|
124
86
|
* Get or create the THREE.TextureLoader (lazy initialization).
|
|
125
87
|
*/
|
|
126
88
|
private _ensureTextureLoader;
|
|
127
|
-
/**
|
|
128
|
-
* Convert a format string (e.g. "png", "jpg", "webp") to a MIME type.
|
|
129
|
-
*/
|
|
130
|
-
private _formatToMime;
|
|
131
89
|
}
|
|
132
90
|
/**
|
|
133
91
|
* Get the correct color space for a Three.js material map property name.
|
|
@@ -139,4 +97,4 @@ declare class TextureCache {
|
|
|
139
97
|
* @returns THREE.SRGBColorSpace or THREE.LinearSRGBColorSpace
|
|
140
98
|
*/
|
|
141
99
|
declare function getColorSpaceForMap(mapName: string): THREE.ColorSpace;
|
|
142
|
-
export { TextureCache, SRGB_TEXTURE_ROLES,
|
|
100
|
+
export { TextureCache, SRGB_TEXTURE_ROLES, getColorSpaceForMap };
|
|
@@ -2,7 +2,7 @@ import * as THREE from "three";
|
|
|
2
2
|
import { BoundingBox } from "./bbox.js";
|
|
3
3
|
import { ObjectGroup, isObjectGroup } from "./objectgroup.js";
|
|
4
4
|
import { MaterialFactory } from "../rendering/material-factory.js";
|
|
5
|
-
import type { ZebraColorScheme, ZebraMappingMode, StudioTextureMapping, Shapes, ColorValue, MaterialAppearance, MaterialXMaterial
|
|
5
|
+
import type { ZebraColorScheme, ZebraMappingMode, StudioTextureMapping, Shapes, ColorValue, MaterialAppearance, MaterialXMaterial } from "../core/types";
|
|
6
6
|
interface ShapeData {
|
|
7
7
|
vertices: Float32Array | number[][];
|
|
8
8
|
normals: Float32Array | number[][];
|
|
@@ -79,7 +79,6 @@ declare class NestedGroup {
|
|
|
79
79
|
groups: GroupsMap;
|
|
80
80
|
clipPlanes: THREE.Plane[] | null;
|
|
81
81
|
materialFactory: MaterialFactory;
|
|
82
|
-
texturesTable: Record<string, TextureEntry> | null;
|
|
83
82
|
materialsTable: Record<string, string | MaterialXMaterial | MaterialAppearance> | null;
|
|
84
83
|
resolvedMaterials: Map<string, MaterialAppearance>;
|
|
85
84
|
/** Cache for threejs-materials entries resolved from the materials table */
|