@visant/extrude3d 0.1.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/README.md +126 -0
- package/dist/fonts.d.ts +14 -0
- package/dist/fonts.d.ts.map +1 -0
- package/dist/fonts.js +62 -0
- package/dist/fonts.js.map +1 -0
- package/dist/geometry.d.ts +64 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +283 -0
- package/dist/geometry.js.map +1 -0
- package/dist/glb.d.ts +40 -0
- package/dist/glb.d.ts.map +1 -0
- package/dist/glb.js +165 -0
- package/dist/glb.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/materials.d.ts +111 -0
- package/dist/materials.d.ts.map +1 -0
- package/dist/materials.js +441 -0
- package/dist/materials.js.map +1 -0
- package/dist/types.d.ts +70 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +64 -0
package/dist/glb.js
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import * as THREE from 'three';
|
|
2
|
+
import * as BufferGeometryUtils from 'three/examples/jsm/utils/BufferGeometryUtils.js';
|
|
3
|
+
import { parseShapesFromSVG, measureFlatMaxDim } from './geometry.js';
|
|
4
|
+
const DEFAULTS = {
|
|
5
|
+
depth: 0.9,
|
|
6
|
+
smoothness: 0.5,
|
|
7
|
+
bevelEnabled: true,
|
|
8
|
+
bevelThickness: 0.5,
|
|
9
|
+
bevelSize: 0.5,
|
|
10
|
+
color: '#c0c0c0',
|
|
11
|
+
metalness: 0.6,
|
|
12
|
+
roughness: 0.3,
|
|
13
|
+
};
|
|
14
|
+
// ── GLB Builder (no browser APIs, no GLTFExporter) ──────────────────────────
|
|
15
|
+
//
|
|
16
|
+
// Serializes a single indexed mesh + one PBR material into a binary glTF (.glb)
|
|
17
|
+
// by hand. Intentionally dependency-free so it runs in plain Node with no DOM —
|
|
18
|
+
// the server export path relies on this.
|
|
19
|
+
function buildGlb(positions, normals, indices, color, metalness, roughness) {
|
|
20
|
+
const posBytes = new Uint8Array(positions.buffer, positions.byteOffset, positions.byteLength);
|
|
21
|
+
const normBytes = new Uint8Array(normals.buffer, normals.byteOffset, normals.byteLength);
|
|
22
|
+
const idxBytes = new Uint8Array(indices.buffer, indices.byteOffset, indices.byteLength);
|
|
23
|
+
const binLength = posBytes.length + normBytes.length + idxBytes.length;
|
|
24
|
+
let min = [Infinity, Infinity, Infinity], max = [-Infinity, -Infinity, -Infinity];
|
|
25
|
+
for (let i = 0; i < positions.length; i += 3) {
|
|
26
|
+
for (let j = 0; j < 3; j++) {
|
|
27
|
+
if (positions[i + j] < min[j])
|
|
28
|
+
min[j] = positions[i + j];
|
|
29
|
+
if (positions[i + j] > max[j])
|
|
30
|
+
max[j] = positions[i + j];
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const vertexCount = positions.length / 3;
|
|
34
|
+
const posOffset = 0;
|
|
35
|
+
const normOffset = posBytes.length;
|
|
36
|
+
const idxOffset = normOffset + normBytes.length;
|
|
37
|
+
const gltf = {
|
|
38
|
+
asset: { version: '2.0', generator: 'Visant Studio3D Server' },
|
|
39
|
+
scene: 0,
|
|
40
|
+
scenes: [{ nodes: [0] }],
|
|
41
|
+
nodes: [{ mesh: 0, name: 'ExtrudedSVG' }],
|
|
42
|
+
meshes: [{ primitives: [{ attributes: { POSITION: 0, NORMAL: 1 }, indices: 2, material: 0 }] }],
|
|
43
|
+
accessors: [
|
|
44
|
+
{ bufferView: 0, componentType: 5126, count: vertexCount, type: 'VEC3', max: max, min: min },
|
|
45
|
+
{ bufferView: 1, componentType: 5126, count: vertexCount, type: 'VEC3' },
|
|
46
|
+
{ bufferView: 2, componentType: 5125, count: indices.length, type: 'SCALAR' },
|
|
47
|
+
],
|
|
48
|
+
bufferViews: [
|
|
49
|
+
{ buffer: 0, byteOffset: posOffset, byteLength: posBytes.length, target: 34962 },
|
|
50
|
+
{ buffer: 0, byteOffset: normOffset, byteLength: normBytes.length, target: 34962 },
|
|
51
|
+
{ buffer: 0, byteOffset: idxOffset, byteLength: idxBytes.length, target: 34963 },
|
|
52
|
+
],
|
|
53
|
+
buffers: [{ byteLength: binLength }],
|
|
54
|
+
materials: [
|
|
55
|
+
{
|
|
56
|
+
pbrMetallicRoughness: {
|
|
57
|
+
baseColorFactor: [...color, 1],
|
|
58
|
+
metallicFactor: metalness,
|
|
59
|
+
roughnessFactor: roughness,
|
|
60
|
+
},
|
|
61
|
+
name: 'material',
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
};
|
|
65
|
+
const jsonStr = JSON.stringify(gltf);
|
|
66
|
+
const jsonPadded = jsonStr + ' '.repeat((4 - (jsonStr.length % 4)) % 4);
|
|
67
|
+
const jsonBuf = new TextEncoder().encode(jsonPadded);
|
|
68
|
+
const binPadded = binLength + ((4 - (binLength % 4)) % 4);
|
|
69
|
+
const binBuf = new Uint8Array(binPadded);
|
|
70
|
+
binBuf.set(posBytes, posOffset);
|
|
71
|
+
binBuf.set(normBytes, normOffset);
|
|
72
|
+
binBuf.set(idxBytes, idxOffset);
|
|
73
|
+
// GLB header: magic(4) + version(4) + length(4) + jsonChunkLen(4) + jsonChunkType(4) + json + binChunkLen(4) + binChunkType(4) + bin
|
|
74
|
+
const totalLength = 12 + 8 + jsonBuf.length + 8 + binBuf.length;
|
|
75
|
+
const glb = new Uint8Array(totalLength);
|
|
76
|
+
const view = new DataView(glb.buffer);
|
|
77
|
+
let off = 0;
|
|
78
|
+
// Header
|
|
79
|
+
view.setUint32(off, 0x46546c67, true);
|
|
80
|
+
off += 4; // 'glTF'
|
|
81
|
+
view.setUint32(off, 2, true);
|
|
82
|
+
off += 4; // version
|
|
83
|
+
view.setUint32(off, totalLength, true);
|
|
84
|
+
off += 4;
|
|
85
|
+
// JSON chunk
|
|
86
|
+
view.setUint32(off, jsonBuf.length, true);
|
|
87
|
+
off += 4;
|
|
88
|
+
view.setUint32(off, 0x4e4f534a, true);
|
|
89
|
+
off += 4; // 'JSON'
|
|
90
|
+
glb.set(jsonBuf, off);
|
|
91
|
+
off += jsonBuf.length;
|
|
92
|
+
// BIN chunk
|
|
93
|
+
view.setUint32(off, binBuf.length, true);
|
|
94
|
+
off += 4;
|
|
95
|
+
view.setUint32(off, 0x004e4942, true);
|
|
96
|
+
off += 4; // 'BIN\0'
|
|
97
|
+
glb.set(binBuf, off);
|
|
98
|
+
return glb;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* SVG string → extruded, merged, centered geometry serialized as a binary glTF
|
|
102
|
+
* (`.glb`). This is the pure core of the Studio3D server export
|
|
103
|
+
* (`studio3dExportService.svgToGlb`); the service keeps only the DOMParser/JSDOM
|
|
104
|
+
* environment shim and storage. Geometry math (extrude settings, vertex budget)
|
|
105
|
+
* matches the legacy server path exactly — plain `computeVertexNormals`, no
|
|
106
|
+
* crease smoothing, no bevel clamp.
|
|
107
|
+
*
|
|
108
|
+
* Returns the GLB bytes plus the geometry arrays. Throws if the SVG yields no
|
|
109
|
+
* shapes or the merge fails. Requires a DOM `DOMParser` to be available (the
|
|
110
|
+
* server installs one via JSDOM before calling).
|
|
111
|
+
*/
|
|
112
|
+
export function svgToGlb(svgString, opts = {}) {
|
|
113
|
+
const o = { ...DEFAULTS, ...opts };
|
|
114
|
+
const allShapes = parseShapesFromSVG(svgString);
|
|
115
|
+
if (allShapes.length === 0)
|
|
116
|
+
throw new Error('No shapes found in SVG');
|
|
117
|
+
const maxFlatDim = measureFlatMaxDim(allShapes);
|
|
118
|
+
const scaledDepth = (o.depth / 10) * maxFlatDim;
|
|
119
|
+
const bevelScale = Math.min(maxFlatDim * 0.05, 1);
|
|
120
|
+
const idealBevel = Math.round(4 + o.smoothness * 8);
|
|
121
|
+
const idealCurve = Math.round(32 + o.smoothness * 64);
|
|
122
|
+
const budget = 600_000;
|
|
123
|
+
const perShape = Math.max(Math.floor(budget / Math.max(allShapes.length, 1)), 500);
|
|
124
|
+
const est = idealBevel * idealCurve * 6;
|
|
125
|
+
const red = est > perShape ? Math.sqrt(perShape / est) : 1;
|
|
126
|
+
const extrudeSettings = {
|
|
127
|
+
depth: scaledDepth,
|
|
128
|
+
bevelEnabled: o.bevelEnabled,
|
|
129
|
+
bevelThickness: bevelScale * o.bevelThickness,
|
|
130
|
+
bevelSize: bevelScale * o.bevelSize,
|
|
131
|
+
bevelSegments: Math.max(2, Math.min(Math.round(idealBevel * red), 64)),
|
|
132
|
+
curveSegments: Math.max(8, Math.min(Math.round(idealCurve * red), 128)),
|
|
133
|
+
};
|
|
134
|
+
const geometries = allShapes.map((shape) => {
|
|
135
|
+
const geo = new THREE.ExtrudeGeometry(shape, extrudeSettings);
|
|
136
|
+
geo.computeVertexNormals();
|
|
137
|
+
return geo;
|
|
138
|
+
});
|
|
139
|
+
// Merge all geometries
|
|
140
|
+
const merged = BufferGeometryUtils.mergeGeometries(geometries, false);
|
|
141
|
+
geometries.forEach((g) => g.dispose());
|
|
142
|
+
if (!merged)
|
|
143
|
+
throw new Error('Failed to merge geometries');
|
|
144
|
+
// Center
|
|
145
|
+
merged.computeBoundingBox();
|
|
146
|
+
const center = new THREE.Vector3();
|
|
147
|
+
merged.boundingBox.getCenter(center);
|
|
148
|
+
merged.translate(-center.x, -center.y, -center.z);
|
|
149
|
+
// Extract arrays
|
|
150
|
+
const nonIndexed = merged.index ? merged.toNonIndexed() : merged;
|
|
151
|
+
nonIndexed.computeVertexNormals();
|
|
152
|
+
const positions = nonIndexed.attributes.position.array;
|
|
153
|
+
const normals = nonIndexed.attributes.normal.array;
|
|
154
|
+
const vertCount = positions.length / 3;
|
|
155
|
+
const indices = new Uint32Array(vertCount);
|
|
156
|
+
for (let i = 0; i < vertCount; i++)
|
|
157
|
+
indices[i] = i;
|
|
158
|
+
const c = new THREE.Color(o.color);
|
|
159
|
+
const glb = buildGlb(positions, normals, indices, [c.r, c.g, c.b], o.metalness, o.roughness);
|
|
160
|
+
merged.dispose();
|
|
161
|
+
if (nonIndexed !== merged)
|
|
162
|
+
nonIndexed.dispose();
|
|
163
|
+
return { glb, positions, normals, indices };
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=glb.js.map
|
package/dist/glb.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glb.js","sourceRoot":"","sources":["../src/glb.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,mBAAmB,MAAM,iDAAiD,CAAC;AACvF,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAkBtE,MAAM,QAAQ,GAA8B;IAC1C,KAAK,EAAE,GAAG;IACV,UAAU,EAAE,GAAG;IACf,YAAY,EAAE,IAAI;IAClB,cAAc,EAAE,GAAG;IACnB,SAAS,EAAE,GAAG;IACd,KAAK,EAAE,SAAS;IAChB,SAAS,EAAE,GAAG;IACd,SAAS,EAAE,GAAG;CACf,CAAC;AAcF,+EAA+E;AAC/E,EAAE;AACF,gFAAgF;AAChF,gFAAgF;AAChF,yCAAyC;AAEzC,SAAS,QAAQ,CACf,SAAuB,EACvB,OAAqB,EACrB,OAAoB,EACpB,KAAe,EACf,SAAiB,EACjB,SAAiB;IAEjB,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,CAAC,UAAU,CAAC,CAAC;IAC9F,MAAM,SAAS,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACzF,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IACxF,MAAM,SAAS,GAAG,QAAQ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AAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE;QAAE,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;IAEnD,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;IACnC,MAAM,GAAG,GAAG,QAAQ,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;IAE7F,MAAM,CAAC,OAAO,EAAE,CAAC;IACjB,IAAI,UAAU,KAAK,MAAM;QAAE,UAAU,CAAC,OAAO,EAAE,CAAC;IAEhD,OAAO,EAAE,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC;AAC9C,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type { BevelOptions, BuildExtrudedGeometryOptions, ExtrudedGeometryResult, OpenTypeFontLike, OpenTypePathLike, OpenTypeGlyphLike, } from './types.js';
|
|
2
|
+
export { buildExtrudedGeometry, buildExtrudeSettings, measureFlatMaxDim, parseShapesFromSVG, smoothCreaseNormals, recomputeTriplanarUVs, isViewBoxRect, type ExtrudeSettings, } from './geometry.js';
|
|
3
|
+
export { materialPresets, MATERIAL_UI, MATERIAL_LIB, resolveMaterial, getSimpleMaterialProps, type MaterialPresetDef, type MaterialUiId, type MaterialCategory, type MaterialUiEntry, type MaterialLibEntry, type ResolvedMaterial, type MaterialOverrides, type SimpleMaterialProps, } from './materials.js';
|
|
4
|
+
export { textToSvg } from './fonts.js';
|
|
5
|
+
export { svgToGlb, type SvgToGlbOptions, type GlbResult } from './glb.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,YAAY,EACZ,4BAA4B,EAC5B,sBAAsB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,GAClB,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,EACb,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,eAAe,EACf,sBAAsB,EACtB,KAAK,iBAAiB,EACtB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,KAAK,SAAS,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { buildExtrudedGeometry, buildExtrudeSettings, measureFlatMaxDim, parseShapesFromSVG, smoothCreaseNormals, recomputeTriplanarUVs, isViewBoxRect, } from './geometry.js';
|
|
2
|
+
export { materialPresets, MATERIAL_UI, MATERIAL_LIB, resolveMaterial, getSimpleMaterialProps, } from './materials.js';
|
|
3
|
+
export { textToSvg } from './fonts.js';
|
|
4
|
+
export { svgToGlb } from './glb.js';
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,aAAa,GAEd,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,eAAe,EACf,WAAW,EACX,YAAY,EACZ,eAAe,EACf,sBAAsB,GASvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,OAAO,EAAE,QAAQ,EAAwC,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
export interface MaterialPresetDef {
|
|
2
|
+
label: string;
|
|
3
|
+
metalness: number;
|
|
4
|
+
roughness: number;
|
|
5
|
+
opacity: number;
|
|
6
|
+
transparent: boolean;
|
|
7
|
+
emissiveIntensity?: number;
|
|
8
|
+
clearcoat?: number;
|
|
9
|
+
clearcoatRoughness?: number;
|
|
10
|
+
sheen?: number;
|
|
11
|
+
sheenRoughness?: number;
|
|
12
|
+
sheenColor?: string;
|
|
13
|
+
transmission?: number;
|
|
14
|
+
thickness?: number;
|
|
15
|
+
ior?: number;
|
|
16
|
+
iridescence?: number;
|
|
17
|
+
iridescenceIOR?: number;
|
|
18
|
+
reflectivity?: number;
|
|
19
|
+
}
|
|
20
|
+
export declare const materialPresets: Record<string, MaterialPresetDef>;
|
|
21
|
+
export type MaterialUiId = keyof typeof materialPresets;
|
|
22
|
+
export type MaterialCategory = 'basic' | 'metals' | 'surfaces' | 'glass' | 'special';
|
|
23
|
+
export interface MaterialUiEntry {
|
|
24
|
+
id: MaterialUiId;
|
|
25
|
+
category: MaterialCategory;
|
|
26
|
+
/** Swatch / default color applied on selection. Optional. */
|
|
27
|
+
color?: string;
|
|
28
|
+
/** Display label override; defaults to `materialPresets[id].label`. */
|
|
29
|
+
label?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Curated, ordered subset of materials surfaced in the Studio3D UI, grouped by
|
|
33
|
+
* category. Ordering and grouping are intentional and load-bearing for the UI.
|
|
34
|
+
*/
|
|
35
|
+
export declare const MATERIAL_UI: MaterialUiEntry[];
|
|
36
|
+
export interface MaterialLibEntry extends MaterialUiEntry {
|
|
37
|
+
label: string;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Fully-resolved UI material list: every entry carries a concrete `label`
|
|
41
|
+
* (override or the PBR-derived default). This is the single list the Studio3D
|
|
42
|
+
* panels iterate over.
|
|
43
|
+
*/
|
|
44
|
+
export declare const MATERIAL_LIB: MaterialLibEntry[];
|
|
45
|
+
export interface ResolvedMaterial {
|
|
46
|
+
preset: string;
|
|
47
|
+
metalness: number;
|
|
48
|
+
roughness: number;
|
|
49
|
+
opacity: number;
|
|
50
|
+
transparent: boolean;
|
|
51
|
+
wireframe: boolean;
|
|
52
|
+
emissiveIntensity?: number;
|
|
53
|
+
clearcoat?: number;
|
|
54
|
+
clearcoatRoughness?: number;
|
|
55
|
+
sheen?: number;
|
|
56
|
+
sheenRoughness?: number;
|
|
57
|
+
sheenColor?: string;
|
|
58
|
+
transmission?: number;
|
|
59
|
+
thickness?: number;
|
|
60
|
+
ior?: number;
|
|
61
|
+
iridescence?: number;
|
|
62
|
+
iridescenceIOR?: number;
|
|
63
|
+
reflectivity?: number;
|
|
64
|
+
}
|
|
65
|
+
export interface MaterialOverrides {
|
|
66
|
+
metalness?: number;
|
|
67
|
+
roughness?: number;
|
|
68
|
+
opacity?: number;
|
|
69
|
+
emissiveIntensity?: number;
|
|
70
|
+
wireframe?: boolean;
|
|
71
|
+
clearcoat?: number;
|
|
72
|
+
clearcoatRoughness?: number;
|
|
73
|
+
sheen?: number;
|
|
74
|
+
sheenRoughness?: number;
|
|
75
|
+
sheenColor?: string;
|
|
76
|
+
transmission?: number;
|
|
77
|
+
thickness?: number;
|
|
78
|
+
ior?: number;
|
|
79
|
+
iridescence?: number;
|
|
80
|
+
iridescenceIOR?: number;
|
|
81
|
+
reflectivity?: number;
|
|
82
|
+
}
|
|
83
|
+
export declare function resolveMaterial(preset: string, overrides: MaterialOverrides): ResolvedMaterial;
|
|
84
|
+
/**
|
|
85
|
+
* Flat prop bag for a `<meshPhysicalMaterial>` rendered from a preset + color,
|
|
86
|
+
* with no texture maps, shaders, blend modes, or shape-specific tweaks. This is
|
|
87
|
+
* the "light" material path used by simple consumers (e.g. the Playground 3D
|
|
88
|
+
* scene) that want preset-driven PBR without the full `ExtrudedSVG` pipeline
|
|
89
|
+
* (which is store-coupled and carries texture/fresnel/blend logic).
|
|
90
|
+
*
|
|
91
|
+
* Single source of truth for the preset→material-prop mapping so consumers stop
|
|
92
|
+
* re-deriving it inline. Pure: depends only on `materialPresets` data.
|
|
93
|
+
*/
|
|
94
|
+
export interface SimpleMaterialProps {
|
|
95
|
+
color: string;
|
|
96
|
+
metalness: number;
|
|
97
|
+
roughness: number;
|
|
98
|
+
opacity: number;
|
|
99
|
+
transparent: boolean;
|
|
100
|
+
emissiveIntensity: number;
|
|
101
|
+
emissive: string;
|
|
102
|
+
clearcoat: number;
|
|
103
|
+
clearcoatRoughness: number;
|
|
104
|
+
sheen: number;
|
|
105
|
+
sheenRoughness: number;
|
|
106
|
+
transmission: number;
|
|
107
|
+
ior: number;
|
|
108
|
+
iridescence: number;
|
|
109
|
+
}
|
|
110
|
+
export declare function getSimpleMaterialProps(preset: string, color: string): SimpleMaterialProps;
|
|
111
|
+
//# sourceMappingURL=materials.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"materials.d.ts","sourceRoot":"","sources":["../src/materials.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,OAAO,CAAC;IACrB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,KAAK,CAAC,EAA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