poppygl 0.0.16 → 0.0.17
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/index.d.ts +8 -2
- package/dist/index.js +20 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -53,6 +53,12 @@ interface GLTFScene {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
declare const DEFAULT_LIGHT_DIR: readonly [-0.4, -0.9, -0.2];
|
|
56
|
+
/**
|
|
57
|
+
* Convert a hex color string to RGB array with values 0-1
|
|
58
|
+
* @param hex - Hex color string like "#ffffff" or "ffffff"
|
|
59
|
+
* @returns RGB array [r, g, b] with values 0-1, or null if invalid
|
|
60
|
+
*/
|
|
61
|
+
declare function hexToRgb(hex: string): [number, number, number] | null;
|
|
56
62
|
interface RenderOptions {
|
|
57
63
|
width: number;
|
|
58
64
|
height: number;
|
|
@@ -63,7 +69,7 @@ interface RenderOptions {
|
|
|
63
69
|
lightDir: readonly [number, number, number];
|
|
64
70
|
camPos?: readonly [number, number, number] | null;
|
|
65
71
|
lookAt?: readonly [number, number, number] | null;
|
|
66
|
-
backgroundColor?: readonly [number, number, number] | null;
|
|
72
|
+
backgroundColor?: readonly [number, number, number] | string | null;
|
|
67
73
|
grid?: boolean | GridOptions;
|
|
68
74
|
}
|
|
69
75
|
type RenderOptionsInput = Partial<RenderOptions>;
|
|
@@ -181,4 +187,4 @@ declare function renderGLTFToPNGBuffer(gltfPathOrString: string, options?: Rende
|
|
|
181
187
|
|
|
182
188
|
declare function renderSceneFromGLTF(scene: GLTFScene, options?: RenderOptionsInput, imageFactory?: ImageFactory): RenderResult;
|
|
183
189
|
|
|
184
|
-
export { type BitmapLike, type Camera, DEFAULT_LIGHT_DIR, DEFAULT_RENDER_OPTIONS, type DrawCall, type FetchLike, type GLTFResources, type GLTFScene, type GridOptions, type ImageFactory, type LightSettings, type LoadGLTFWithResourcesFromURLOptions, type Material, type MutableRGBA, type RGBA, type RenderGLTFToPNGBufferFromGLBBufferOptions, type RenderGLTFToPNGBufferFromURLOptions, type RenderOptions, type RenderOptionsInput, type RenderResult, SoftwareRenderer, bufferFromDataURI, buildCamera, computeSmoothNormals, computeWorldAABB, createGrid, createInfiniteGrid, createSceneFromGLTF, createUint8Bitmap, decodeImageFromBuffer, drawInfiniteGrid, encodePNGToBuffer, getDefaultRenderOptions, isJPG, isPNG, loadGLTFWithResourcesFromURL, pureImageFactory, renderDrawCalls, renderGLTFToPNGBuffer, renderGLTFToPNGBufferFromGLBBuffer, renderGLTFToPNGBufferFromURL, renderSceneFromGLTF, resolveRenderOptions };
|
|
190
|
+
export { type BitmapLike, type Camera, DEFAULT_LIGHT_DIR, DEFAULT_RENDER_OPTIONS, type DrawCall, type FetchLike, type GLTFResources, type GLTFScene, type GridOptions, type ImageFactory, type LightSettings, type LoadGLTFWithResourcesFromURLOptions, type Material, type MutableRGBA, type RGBA, type RenderGLTFToPNGBufferFromGLBBufferOptions, type RenderGLTFToPNGBufferFromURLOptions, type RenderOptions, type RenderOptionsInput, type RenderResult, SoftwareRenderer, bufferFromDataURI, buildCamera, computeSmoothNormals, computeWorldAABB, createGrid, createInfiniteGrid, createSceneFromGLTF, createUint8Bitmap, decodeImageFromBuffer, drawInfiniteGrid, encodePNGToBuffer, getDefaultRenderOptions, hexToRgb, isJPG, isPNG, loadGLTFWithResourcesFromURL, pureImageFactory, renderDrawCalls, renderGLTFToPNGBuffer, renderGLTFToPNGBufferFromGLBBuffer, renderGLTFToPNGBufferFromURL, renderSceneFromGLTF, resolveRenderOptions };
|
package/dist/index.js
CHANGED
|
@@ -134,6 +134,16 @@ var createUint8Bitmap = (width, height) => ({
|
|
|
134
134
|
|
|
135
135
|
// lib/render/getDefaultRenderOptions.ts
|
|
136
136
|
var DEFAULT_LIGHT_DIR = [-0.4, -0.9, -0.2];
|
|
137
|
+
function hexToRgb(hex) {
|
|
138
|
+
const cleanHex = hex.replace(/^#/, "");
|
|
139
|
+
if (!/^[0-9A-Fa-f]{6}$/.test(cleanHex)) {
|
|
140
|
+
return null;
|
|
141
|
+
}
|
|
142
|
+
const r = Number.parseInt(cleanHex.substring(0, 2), 16) / 255;
|
|
143
|
+
const g = Number.parseInt(cleanHex.substring(2, 4), 16) / 255;
|
|
144
|
+
const b = Number.parseInt(cleanHex.substring(4, 6), 16) / 255;
|
|
145
|
+
return [r, g, b];
|
|
146
|
+
}
|
|
137
147
|
var DEFAULT_RENDER_OPTIONS = {
|
|
138
148
|
width: 800,
|
|
139
149
|
height: 600,
|
|
@@ -765,8 +775,16 @@ function renderDrawCalls(drawCalls, optionsInput = {}, imageFactory = createUint
|
|
|
765
775
|
options.height,
|
|
766
776
|
imageFactory
|
|
767
777
|
);
|
|
778
|
+
let rgb = null;
|
|
768
779
|
if (options.backgroundColor) {
|
|
769
|
-
|
|
780
|
+
if (typeof options.backgroundColor === "string") {
|
|
781
|
+
rgb = hexToRgb(options.backgroundColor);
|
|
782
|
+
} else {
|
|
783
|
+
rgb = options.backgroundColor;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
if (rgb) {
|
|
787
|
+
const [r, g, b] = rgb;
|
|
770
788
|
renderer.clear([
|
|
771
789
|
Math.round(r * 255),
|
|
772
790
|
Math.round(g * 255),
|
|
@@ -1603,6 +1621,7 @@ export {
|
|
|
1603
1621
|
drawInfiniteGrid,
|
|
1604
1622
|
encodePNGToBuffer,
|
|
1605
1623
|
getDefaultRenderOptions,
|
|
1624
|
+
hexToRgb,
|
|
1606
1625
|
isJPG,
|
|
1607
1626
|
isPNG,
|
|
1608
1627
|
loadGLTFWithResourcesFromURL,
|