poppygl 0.0.37 → 0.0.38
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 +22 -0
- package/dist/index.d.ts +69 -64
- package/dist/index.js +20 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -245,6 +245,28 @@ Pass `explosionLines` to any render entrypoint to draw polylines between assembl
|
|
|
245
245
|
and displaced part positions. The caller moves the geometry and supplies the
|
|
246
246
|
points in the same glTF scene frame and units (normally right-handed, +Y up).
|
|
247
247
|
|
|
248
|
+
The selected glTF scene can embed the same setting in `extras.poppygl.explosionLines`:
|
|
249
|
+
|
|
250
|
+
```json
|
|
251
|
+
{
|
|
252
|
+
"scene": 0,
|
|
253
|
+
"scenes": [{
|
|
254
|
+
"nodes": [0],
|
|
255
|
+
"extras": {
|
|
256
|
+
"poppygl": {
|
|
257
|
+
"explosionLines": [{ "points": [[0, 0, 0], [0, 20, 0]], "dashed": true }]
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}]
|
|
261
|
+
}
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
`renderSceneFromGLTF`, the URL renderer, and the GLB renderer use these guides
|
|
265
|
+
when `explosionLines` is omitted. An explicit list replaces the embedded guides;
|
|
266
|
+
`null` or `[]` hides them. Points are already in glTF world coordinates and are
|
|
267
|
+
not transformed by individual nodes. No guide meshes are required, and other
|
|
268
|
+
glTF viewers may ignore this optional metadata.
|
|
269
|
+
|
|
248
270
|
This lamp is adapted from [core's reference-surface lamp](https://github.com/tscircuit/core/blob/81bef4337570e3ac4d7dd6d30ab63481304e8147/tests/assembly/fixtures/reference-surface-lamp.tsx).
|
|
249
271
|
Its base, hollow blue stem, and bulb stay in place while the hollow shade,
|
|
250
272
|
mounting collar, and three spokes move together by **+60 mm on scene Y**. The
|
package/dist/index.d.ts
CHANGED
|
@@ -1,69 +1,5 @@
|
|
|
1
1
|
import { mat4 } from 'gl-matrix';
|
|
2
2
|
|
|
3
|
-
type RGBA = readonly [number, number, number, number];
|
|
4
|
-
type MutableRGBA = [number, number, number, number];
|
|
5
|
-
interface BitmapLike {
|
|
6
|
-
width: number;
|
|
7
|
-
height: number;
|
|
8
|
-
data: Uint8Array | Uint8ClampedArray;
|
|
9
|
-
}
|
|
10
|
-
type ImageFactory = (width: number, height: number) => BitmapLike;
|
|
11
|
-
declare const createUint8Bitmap: ImageFactory;
|
|
12
|
-
|
|
13
|
-
interface Material {
|
|
14
|
-
baseColorFactor: [number, number, number, number];
|
|
15
|
-
baseColorTexture: BitmapLike | null;
|
|
16
|
-
/** Repeat rather than clamp the base-color texture (used by section hatching). */
|
|
17
|
-
baseColorTextureWrap?: "repeat" | "clamp";
|
|
18
|
-
metallicFactor?: number;
|
|
19
|
-
roughnessFactor?: number;
|
|
20
|
-
emissiveFactor?: [number, number, number];
|
|
21
|
-
emissiveTexture?: BitmapLike | null;
|
|
22
|
-
emissiveStrength?: number;
|
|
23
|
-
alphaMode?: "OPAQUE" | "MASK" | "BLEND";
|
|
24
|
-
alphaCutoff?: number;
|
|
25
|
-
}
|
|
26
|
-
interface DrawCall {
|
|
27
|
-
/** Generated section cap; preserve its hatch material in outline style. */
|
|
28
|
-
outlineSectionCap?: boolean;
|
|
29
|
-
positions: Float32Array;
|
|
30
|
-
normals: Float32Array | null;
|
|
31
|
-
uvs: Float32Array | null;
|
|
32
|
-
indices: Uint32Array | null;
|
|
33
|
-
model: mat4;
|
|
34
|
-
material: Material;
|
|
35
|
-
colors?: Float32Array | null;
|
|
36
|
-
mode?: number;
|
|
37
|
-
showHiddenEdges?: boolean;
|
|
38
|
-
/** Source triangle third vertices for each extracted edge segment. */
|
|
39
|
-
edgeAdjacentVertices?: number[][];
|
|
40
|
-
}
|
|
41
|
-
interface GridOptions {
|
|
42
|
-
size?: number | readonly [number, number, number];
|
|
43
|
-
divisions?: number;
|
|
44
|
-
color?: readonly [number, number, number];
|
|
45
|
-
offset?: Partial<{
|
|
46
|
-
x: number;
|
|
47
|
-
y: number;
|
|
48
|
-
z: number;
|
|
49
|
-
}>;
|
|
50
|
-
infiniteGrid?: boolean;
|
|
51
|
-
cellSize?: number;
|
|
52
|
-
sectionSize?: number;
|
|
53
|
-
fadeDistance?: number;
|
|
54
|
-
fadeStrength?: number;
|
|
55
|
-
gridColor?: readonly [number, number, number];
|
|
56
|
-
sectionColor?: readonly [number, number, number];
|
|
57
|
-
}
|
|
58
|
-
interface GLTFResources {
|
|
59
|
-
buffers: Uint8Array[];
|
|
60
|
-
images: BitmapLike[];
|
|
61
|
-
}
|
|
62
|
-
interface GLTFScene {
|
|
63
|
-
drawCalls: DrawCall[];
|
|
64
|
-
gltf: any;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
3
|
type SectionAxis = "x" | "y" | "z";
|
|
68
4
|
/** Axis-aligned plane in world/glTF coordinates, in model scene units. */
|
|
69
5
|
interface OutlineSection {
|
|
@@ -162,6 +98,72 @@ type RenderOptionsInput = Partial<RenderOptions>;
|
|
|
162
98
|
declare const DEFAULT_RENDER_OPTIONS: RenderOptions;
|
|
163
99
|
declare function getDefaultRenderOptions(): RenderOptions;
|
|
164
100
|
|
|
101
|
+
type RGBA = readonly [number, number, number, number];
|
|
102
|
+
type MutableRGBA = [number, number, number, number];
|
|
103
|
+
interface BitmapLike {
|
|
104
|
+
width: number;
|
|
105
|
+
height: number;
|
|
106
|
+
data: Uint8Array | Uint8ClampedArray;
|
|
107
|
+
}
|
|
108
|
+
type ImageFactory = (width: number, height: number) => BitmapLike;
|
|
109
|
+
declare const createUint8Bitmap: ImageFactory;
|
|
110
|
+
|
|
111
|
+
interface Material {
|
|
112
|
+
baseColorFactor: [number, number, number, number];
|
|
113
|
+
baseColorTexture: BitmapLike | null;
|
|
114
|
+
/** Repeat rather than clamp the base-color texture (used by section hatching). */
|
|
115
|
+
baseColorTextureWrap?: "repeat" | "clamp";
|
|
116
|
+
metallicFactor?: number;
|
|
117
|
+
roughnessFactor?: number;
|
|
118
|
+
emissiveFactor?: [number, number, number];
|
|
119
|
+
emissiveTexture?: BitmapLike | null;
|
|
120
|
+
emissiveStrength?: number;
|
|
121
|
+
alphaMode?: "OPAQUE" | "MASK" | "BLEND";
|
|
122
|
+
alphaCutoff?: number;
|
|
123
|
+
}
|
|
124
|
+
interface DrawCall {
|
|
125
|
+
/** Generated section cap; preserve its hatch material in outline style. */
|
|
126
|
+
outlineSectionCap?: boolean;
|
|
127
|
+
positions: Float32Array;
|
|
128
|
+
normals: Float32Array | null;
|
|
129
|
+
uvs: Float32Array | null;
|
|
130
|
+
indices: Uint32Array | null;
|
|
131
|
+
model: mat4;
|
|
132
|
+
material: Material;
|
|
133
|
+
colors?: Float32Array | null;
|
|
134
|
+
mode?: number;
|
|
135
|
+
showHiddenEdges?: boolean;
|
|
136
|
+
/** Source triangle third vertices for each extracted edge segment. */
|
|
137
|
+
edgeAdjacentVertices?: number[][];
|
|
138
|
+
}
|
|
139
|
+
interface GridOptions {
|
|
140
|
+
size?: number | readonly [number, number, number];
|
|
141
|
+
divisions?: number;
|
|
142
|
+
color?: readonly [number, number, number];
|
|
143
|
+
offset?: Partial<{
|
|
144
|
+
x: number;
|
|
145
|
+
y: number;
|
|
146
|
+
z: number;
|
|
147
|
+
}>;
|
|
148
|
+
infiniteGrid?: boolean;
|
|
149
|
+
cellSize?: number;
|
|
150
|
+
sectionSize?: number;
|
|
151
|
+
fadeDistance?: number;
|
|
152
|
+
fadeStrength?: number;
|
|
153
|
+
gridColor?: readonly [number, number, number];
|
|
154
|
+
sectionColor?: readonly [number, number, number];
|
|
155
|
+
}
|
|
156
|
+
interface GLTFResources {
|
|
157
|
+
buffers: Uint8Array[];
|
|
158
|
+
images: BitmapLike[];
|
|
159
|
+
}
|
|
160
|
+
interface GLTFScene {
|
|
161
|
+
/** Selected scene extras.poppygl.explosionLines, in glTF world coordinates. */
|
|
162
|
+
explosionLines?: readonly ExplosionLine[];
|
|
163
|
+
drawCalls: DrawCall[];
|
|
164
|
+
gltf: any;
|
|
165
|
+
}
|
|
166
|
+
|
|
165
167
|
interface Camera {
|
|
166
168
|
view: mat4;
|
|
167
169
|
proj: mat4;
|
|
@@ -311,6 +313,9 @@ declare function renderGLTFToPNGFromURL(url: string, options?: RenderGLTFToPNGFr
|
|
|
311
313
|
type RenderGLTFToPNGFromGLBOptions = RenderOptionsInput;
|
|
312
314
|
declare function renderGLTFToPNGFromGLB(glb: ArrayBuffer | Uint8Array, options?: RenderGLTFToPNGFromGLBOptions): Promise<Uint8Array>;
|
|
313
315
|
|
|
316
|
+
/** Render the selected glTF scene's guides in scene-world coordinates.
|
|
317
|
+
* Explicit options override extras; null or [] disables embedded guides.
|
|
318
|
+
*/
|
|
314
319
|
declare function renderSceneFromGLTF(scene: GLTFScene, options?: RenderOptionsInput, imageFactory?: ImageFactory): RenderResult;
|
|
315
320
|
|
|
316
321
|
export { type BitmapLike, type Camera, type CameraRotation, type CameraUp, DEFAULT_LIGHT_DIR, DEFAULT_RENDER_OPTIONS, type DebugPoint, type DrawCall, type ExplosionLine, type FetchLike, type GLTFResources, type GLTFScene, type GridOptions, type ImageFactory, type LightSettings, type LineRenderOptions, type LoadGLTFWithResourcesFromURLOptions, type Material, type MutableRGBA, type OutlineSection, type RGBA, type RenderGLTFToPNGFromGLBOptions, type RenderGLTFToPNGFromURLOptions, type RenderOptions, type RenderOptionsInput, type RenderResult, SoftwareRenderer, bufferFromDataURI, buildCamera, computeSmoothNormals, computeWorldAABB, createEdgeDrawCall, createGrid, createInfiniteGrid, createOutlineSection, createSceneFromGLTF, createUint8Bitmap, decodeImageFromBuffer, drawInfiniteGrid, encodePNG, getDefaultRenderOptions, hexToRgb, isJPG, isPNG, loadGLTFWithResourcesFromURL, renderDrawCalls, renderGLTFToPNGFromGLB, renderGLTFToPNGFromURL, renderSceneFromGLTF, resolveRenderOptions };
|
package/dist/index.js
CHANGED
|
@@ -3492,7 +3492,11 @@ function createSceneFromGLTF(gltf, resources) {
|
|
|
3492
3492
|
for (const rootIndex of scene.nodes || []) {
|
|
3493
3493
|
traverse(rootIndex, identity);
|
|
3494
3494
|
}
|
|
3495
|
-
return {
|
|
3495
|
+
return {
|
|
3496
|
+
gltf,
|
|
3497
|
+
drawCalls,
|
|
3498
|
+
explosionLines: scene.extras?.poppygl?.explosionLines
|
|
3499
|
+
};
|
|
3496
3500
|
}
|
|
3497
3501
|
|
|
3498
3502
|
// lib/gltf/resourceUtils.ts
|
|
@@ -3732,6 +3736,18 @@ async function encodePNG(image) {
|
|
|
3732
3736
|
});
|
|
3733
3737
|
}
|
|
3734
3738
|
|
|
3739
|
+
// lib/render/renderSceneFromGLTF.ts
|
|
3740
|
+
function renderSceneFromGLTF(scene, options = {}, imageFactory) {
|
|
3741
|
+
return renderDrawCalls(
|
|
3742
|
+
scene.drawCalls,
|
|
3743
|
+
{
|
|
3744
|
+
...options,
|
|
3745
|
+
explosionLines: options.explosionLines === void 0 ? scene.explosionLines : options.explosionLines
|
|
3746
|
+
},
|
|
3747
|
+
imageFactory
|
|
3748
|
+
);
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3735
3751
|
// lib/render/renderGLTFToPNGFromURL.ts
|
|
3736
3752
|
async function renderGLTFToPNGFromURL(url, options = {}) {
|
|
3737
3753
|
const { fetchImpl, ...renderOptions } = options;
|
|
@@ -3739,8 +3755,8 @@ async function renderGLTFToPNGFromURL(url, options = {}) {
|
|
|
3739
3755
|
fetchImpl
|
|
3740
3756
|
});
|
|
3741
3757
|
const scene = createSceneFromGLTF(gltf, resources);
|
|
3742
|
-
const { bitmap } =
|
|
3743
|
-
scene
|
|
3758
|
+
const { bitmap } = renderSceneFromGLTF(
|
|
3759
|
+
scene,
|
|
3744
3760
|
renderOptions,
|
|
3745
3761
|
createUint8Bitmap
|
|
3746
3762
|
);
|
|
@@ -3817,18 +3833,9 @@ async function renderGLTFToPNGFromGLB(glb, options = {}) {
|
|
|
3817
3833
|
})
|
|
3818
3834
|
);
|
|
3819
3835
|
const scene = createSceneFromGLTF(gltf, { buffers, images });
|
|
3820
|
-
const { bitmap } =
|
|
3821
|
-
scene.drawCalls,
|
|
3822
|
-
options,
|
|
3823
|
-
createUint8Bitmap
|
|
3824
|
-
);
|
|
3836
|
+
const { bitmap } = renderSceneFromGLTF(scene, options, createUint8Bitmap);
|
|
3825
3837
|
return encodePNG(bitmap);
|
|
3826
3838
|
}
|
|
3827
|
-
|
|
3828
|
-
// lib/index.ts
|
|
3829
|
-
function renderSceneFromGLTF(scene, options, imageFactory) {
|
|
3830
|
-
return renderDrawCalls(scene.drawCalls, options, imageFactory);
|
|
3831
|
-
}
|
|
3832
3839
|
export {
|
|
3833
3840
|
DEFAULT_LIGHT_DIR,
|
|
3834
3841
|
DEFAULT_RENDER_OPTIONS,
|