poppygl 0.0.3 → 0.0.5
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 +127 -0
- package/dist/index.js +5 -3
- package/package.json +5 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { mat4 } from 'gl-matrix';
|
|
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
|
+
declare const DEFAULT_LIGHT_DIR: readonly [-0.4, -0.9, -0.2];
|
|
14
|
+
interface RenderOptions {
|
|
15
|
+
width: number;
|
|
16
|
+
height: number;
|
|
17
|
+
fov: number;
|
|
18
|
+
cull: boolean;
|
|
19
|
+
gamma: boolean;
|
|
20
|
+
ambient: number;
|
|
21
|
+
lightDir: readonly [number, number, number];
|
|
22
|
+
camPos?: readonly [number, number, number] | null;
|
|
23
|
+
lookAt?: readonly [number, number, number] | null;
|
|
24
|
+
}
|
|
25
|
+
type RenderOptionsInput = Partial<RenderOptions>;
|
|
26
|
+
declare const DEFAULT_RENDER_OPTIONS: RenderOptions;
|
|
27
|
+
declare function getDefaultRenderOptions(): RenderOptions;
|
|
28
|
+
|
|
29
|
+
interface Material {
|
|
30
|
+
baseColorFactor: [number, number, number, number];
|
|
31
|
+
baseColorTexture: BitmapLike | null;
|
|
32
|
+
}
|
|
33
|
+
interface DrawCall {
|
|
34
|
+
positions: Float32Array;
|
|
35
|
+
normals: Float32Array | null;
|
|
36
|
+
uvs: Float32Array | null;
|
|
37
|
+
indices: Uint32Array | null;
|
|
38
|
+
model: mat4;
|
|
39
|
+
material: Material;
|
|
40
|
+
}
|
|
41
|
+
interface GLTFResources {
|
|
42
|
+
buffers: Uint8Array[];
|
|
43
|
+
images: BitmapLike[];
|
|
44
|
+
}
|
|
45
|
+
interface GLTFScene {
|
|
46
|
+
drawCalls: DrawCall[];
|
|
47
|
+
gltf: any;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
interface Camera {
|
|
51
|
+
view: mat4;
|
|
52
|
+
proj: mat4;
|
|
53
|
+
}
|
|
54
|
+
declare function buildCamera(drawCalls: DrawCall[], width: number, height: number, fovDeg: number, camPos: readonly [number, number, number] | null | undefined, lookAt: readonly [number, number, number] | null | undefined): Camera;
|
|
55
|
+
|
|
56
|
+
interface RenderResult {
|
|
57
|
+
bitmap: BitmapLike;
|
|
58
|
+
camera: Camera;
|
|
59
|
+
options: RenderOptions;
|
|
60
|
+
}
|
|
61
|
+
declare function renderDrawCalls(drawCalls: DrawCall[], optionsInput?: RenderOptionsInput, imageFactory?: ImageFactory): RenderResult;
|
|
62
|
+
|
|
63
|
+
declare function resolveRenderOptions(options?: RenderOptionsInput): RenderOptions;
|
|
64
|
+
|
|
65
|
+
type GLTF = any;
|
|
66
|
+
declare function createSceneFromGLTF(gltf: GLTF, resources: GLTFResources): GLTFScene;
|
|
67
|
+
|
|
68
|
+
declare function computeSmoothNormals(positions: Float32Array, indices: Uint32Array | null): Float32Array;
|
|
69
|
+
|
|
70
|
+
declare function computeWorldAABB(drawCalls: DrawCall[]): {
|
|
71
|
+
min: number[];
|
|
72
|
+
max: number[];
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
interface FetchLikeResponse {
|
|
76
|
+
ok: boolean;
|
|
77
|
+
status: number;
|
|
78
|
+
statusText: string;
|
|
79
|
+
url?: string;
|
|
80
|
+
arrayBuffer(): Promise<ArrayBuffer>;
|
|
81
|
+
}
|
|
82
|
+
type FetchLike = (input: string, init?: Record<string, unknown>) => Promise<FetchLikeResponse>;
|
|
83
|
+
interface LoadGLTFWithResourcesFromURLOptions {
|
|
84
|
+
fetchImpl?: FetchLike;
|
|
85
|
+
}
|
|
86
|
+
declare function loadGLTFWithResourcesFromURL(url: string, options?: LoadGLTFWithResourcesFromURLOptions): Promise<{
|
|
87
|
+
gltf: any;
|
|
88
|
+
resources: GLTFResources;
|
|
89
|
+
}>;
|
|
90
|
+
|
|
91
|
+
declare function bufferFromDataURI(uri: string): Uint8Array;
|
|
92
|
+
declare function isPNG(filenameOrUri: string): boolean;
|
|
93
|
+
declare function isJPG(filenameOrUri: string): boolean;
|
|
94
|
+
declare function decodeImageFromBuffer(buf: Uint8Array, mimeType?: string | null): Promise<BitmapLike>;
|
|
95
|
+
|
|
96
|
+
interface LightSettings {
|
|
97
|
+
dir: readonly [number, number, number];
|
|
98
|
+
ambient: number;
|
|
99
|
+
}
|
|
100
|
+
declare class SoftwareRenderer {
|
|
101
|
+
readonly width: number;
|
|
102
|
+
readonly height: number;
|
|
103
|
+
readonly bitmap: BitmapLike;
|
|
104
|
+
readonly depth: Float32Array;
|
|
105
|
+
constructor(width: number, height: number, imageFactory?: ImageFactory);
|
|
106
|
+
get buffer(): Uint8Array<ArrayBufferLike> | Uint8ClampedArray<ArrayBufferLike>;
|
|
107
|
+
clear(colorRGBA?: [number, number, number, number]): void;
|
|
108
|
+
setPixel(x: number, y: number, r: number, g: number, b: number, a: number): void;
|
|
109
|
+
sampleTextureNearest(img: BitmapLike | null, u: number, v: number): MutableRGBA;
|
|
110
|
+
perspInterp(attrs: number[][], invWs: number[], lambdas: number[]): number[];
|
|
111
|
+
drawMesh(mesh: DrawCall, camera: Camera, light: LightSettings, material: Material, cullBackFaces?: boolean, gammaOut?: boolean): void;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
declare const pureImageFactory: ImageFactory;
|
|
115
|
+
|
|
116
|
+
declare function encodePNGToBuffer(image: BitmapLike): Promise<Buffer>;
|
|
117
|
+
|
|
118
|
+
interface RenderGLTFToPNGBufferFromURLOptions extends RenderOptionsInput, LoadGLTFWithResourcesFromURLOptions {
|
|
119
|
+
}
|
|
120
|
+
declare function renderGLTFToPNGBufferFromURL(url: string, options?: RenderGLTFToPNGBufferFromURLOptions): Promise<Buffer>;
|
|
121
|
+
|
|
122
|
+
type RenderGLTFToPNGBufferFromGLBBufferOptions = RenderOptionsInput;
|
|
123
|
+
declare function renderGLTFToPNGBufferFromGLBBuffer(glb: ArrayBuffer | Uint8Array, options?: RenderGLTFToPNGBufferFromGLBBufferOptions): Promise<Buffer>;
|
|
124
|
+
|
|
125
|
+
declare function renderSceneFromGLTF(scene: GLTFScene, options?: RenderOptionsInput, imageFactory?: ImageFactory): RenderResult;
|
|
126
|
+
|
|
127
|
+
export { type BitmapLike, type Camera, DEFAULT_LIGHT_DIR, DEFAULT_RENDER_OPTIONS, type DrawCall, type FetchLike, type GLTFResources, type GLTFScene, 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, createSceneFromGLTF, createUint8Bitmap, decodeImageFromBuffer, encodePNGToBuffer, getDefaultRenderOptions, isJPG, isPNG, loadGLTFWithResourcesFromURL, pureImageFactory, renderDrawCalls, renderGLTFToPNGBufferFromGLBBuffer, renderGLTFToPNGBufferFromURL, renderSceneFromGLTF, resolveRenderOptions };
|
package/dist/index.js
CHANGED
|
@@ -742,7 +742,7 @@ function createSceneFromGLTF(gltf, resources) {
|
|
|
742
742
|
}
|
|
743
743
|
|
|
744
744
|
// lib/gltf/resourceUtils.ts
|
|
745
|
-
import { PassThrough } from "stream";
|
|
745
|
+
import { PassThrough } from "readable-stream";
|
|
746
746
|
import * as PImage from "pureimage";
|
|
747
747
|
function bufferFromDataURI(uri) {
|
|
748
748
|
const match = uri.match(/^data:.*?;base64,(.*)$/);
|
|
@@ -773,7 +773,9 @@ async function decodeImageFromBuffer(buf, mimeType) {
|
|
|
773
773
|
return PImage.decodePNGFromStream(bufferToStream(buf));
|
|
774
774
|
if (type === "image/jpeg" || type === "image/jpg")
|
|
775
775
|
return PImage.decodeJPEGFromStream(bufferToStream(buf));
|
|
776
|
-
throw new Error(
|
|
776
|
+
throw new Error(
|
|
777
|
+
`Unsupported embedded image mimeType: ${mimeType ?? "unknown"}`
|
|
778
|
+
);
|
|
777
779
|
}
|
|
778
780
|
|
|
779
781
|
// lib/gltf/parseGLB.ts
|
|
@@ -924,7 +926,7 @@ import * as PImage2 from "pureimage";
|
|
|
924
926
|
var pureImageFactory = (width, height) => PImage2.make(width, height);
|
|
925
927
|
|
|
926
928
|
// lib/image/encodePNGToBuffer.ts
|
|
927
|
-
import { PassThrough as PassThrough2 } from "stream";
|
|
929
|
+
import { PassThrough as PassThrough2 } from "readable-stream";
|
|
928
930
|
import * as PImage3 from "pureimage";
|
|
929
931
|
async function encodePNGToBuffer(image) {
|
|
930
932
|
const passThrough = new PassThrough2();
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "poppygl",
|
|
3
3
|
"main": "dist/index.js",
|
|
4
|
-
"version": "0.0.
|
|
4
|
+
"version": "0.0.5",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/tscircuit/poppygl.git"
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"scripts": {
|
|
13
13
|
"start": "cosmos",
|
|
14
14
|
"build:site": "cosmos-export",
|
|
15
|
-
"build": "tsup-node ./lib/index.ts --format esm",
|
|
15
|
+
"build": "tsup-node ./lib/index.ts --format esm --dts",
|
|
16
16
|
"format": "biome format --write .",
|
|
17
17
|
"format:check": "biome format .",
|
|
18
18
|
"test": "bun test"
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@biomejs/biome": "^2.2.4",
|
|
23
23
|
"@types/bun": "^1.2.23",
|
|
24
|
+
"@types/readable-stream": "^4.0.21",
|
|
24
25
|
"looks-same": "^10.0.1",
|
|
25
26
|
"react": "^19.1.1",
|
|
26
27
|
"react-cosmos": "^7.0.0",
|
|
@@ -34,6 +35,7 @@
|
|
|
34
35
|
},
|
|
35
36
|
"dependencies": {
|
|
36
37
|
"gl-matrix": "^3.4.4",
|
|
37
|
-
"pureimage": "^0.4.18"
|
|
38
|
+
"pureimage": "^0.4.18",
|
|
39
|
+
"readable-stream": "^4.7.0"
|
|
38
40
|
}
|
|
39
41
|
}
|