bloody-engine 1.0.5 → 1.0.6
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 +85 -37
- package/dist/node/core/resource-loader-factory.d.ts +58 -0
- package/dist/node/core/resource-loader-factory.d.ts.map +1 -0
- package/dist/node/core/resource-pipeline.d.ts.map +1 -0
- package/dist/{web → node}/examples/resource-loader-demo.d.ts.map +1 -1
- package/dist/node/index.js +18 -608
- package/dist/{web → node}/public-api.d.ts +0 -3
- package/dist/node/public-api.d.ts.map +1 -0
- package/dist/{web → node}/rendering/rendering-context-factory.d.ts +3 -7
- package/dist/node/rendering/rendering-context-factory.d.ts.map +1 -0
- package/package.json +8 -10
- package/dist/web/core/resource-loader-factory.d.ts +0 -90
- package/dist/web/core/resource-loader-factory.d.ts.map +0 -1
- package/dist/web/core/resource-pipeline.d.ts.map +0 -1
- package/dist/web/index.js +0 -2223
- package/dist/web/index.umd.js +0 -56
- package/dist/web/platforms/browser/browser-context.d.ts +0 -31
- package/dist/web/platforms/browser/browser-context.d.ts.map +0 -1
- package/dist/web/platforms/browser/browser-resource-loader.d.ts +0 -67
- package/dist/web/platforms/browser/browser-resource-loader.d.ts.map +0 -1
- package/dist/web/public-api.d.ts.map +0 -1
- package/dist/web/rendering/rendering-context-factory.d.ts.map +0 -1
- /package/dist/{web → node}/core/buffer.d.ts +0 -0
- /package/dist/{web → node}/core/buffer.d.ts.map +0 -0
- /package/dist/{web → node}/core/grahpic-device.d.ts +0 -0
- /package/dist/{web → node}/core/grahpic-device.d.ts.map +0 -0
- /package/dist/{web → node}/core/index.d.ts +0 -0
- /package/dist/{web → node}/core/index.d.ts.map +0 -0
- /package/dist/{web → node}/core/resource-loader.d.ts +0 -0
- /package/dist/{web → node}/core/resource-loader.d.ts.map +0 -0
- /package/dist/{web → node}/core/resource-pipeline.d.ts +0 -0
- /package/dist/{web → node}/core/shader.d.ts +0 -0
- /package/dist/{web → node}/core/shader.d.ts.map +0 -0
- /package/dist/{web → node}/core/texture.d.ts +0 -0
- /package/dist/{web → node}/core/texture.d.ts.map +0 -0
- /package/dist/{web → node}/demo-node.d.ts +0 -0
- /package/dist/{web → node}/demo-node.d.ts.map +0 -0
- /package/dist/{web → node}/examples/batch-renderer-demo.d.ts +0 -0
- /package/dist/{web → node}/examples/batch-renderer-demo.d.ts.map +0 -0
- /package/dist/{web → node}/examples/projection-examples.d.ts +0 -0
- /package/dist/{web → node}/examples/projection-examples.d.ts.map +0 -0
- /package/dist/{web → node}/examples/resource-loader-demo.d.ts +0 -0
- /package/dist/{web → node}/examples/shader-examples.d.ts +0 -0
- /package/dist/{web → node}/examples/shader-examples.d.ts.map +0 -0
- /package/dist/{web → node}/examples/sprite-batch-renderer-demo.d.ts +0 -0
- /package/dist/{web → node}/examples/sprite-batch-renderer-demo.d.ts.map +0 -0
- /package/dist/{web → node}/index.d.ts +0 -0
- /package/dist/{web → node}/index.d.ts.map +0 -0
- /package/dist/{web → node}/platforms/node/node-context.d.ts +0 -0
- /package/dist/{web → node}/platforms/node/node-context.d.ts.map +0 -0
- /package/dist/{web → node}/platforms/node/node-resource-loader.d.ts +0 -0
- /package/dist/{web → node}/platforms/node/node-resource-loader.d.ts.map +0 -0
- /package/dist/{web → node}/platforms/node/sdl-window.d.ts +0 -0
- /package/dist/{web → node}/platforms/node/sdl-window.d.ts.map +0 -0
- /package/dist/{web → node}/projection.test.d.ts +0 -0
- /package/dist/{web → node}/projection.test.d.ts.map +0 -0
- /package/dist/{web → node}/rendering/batch-renderer.d.ts +0 -0
- /package/dist/{web → node}/rendering/batch-renderer.d.ts.map +0 -0
- /package/dist/{web → node}/rendering/camera.d.ts +0 -0
- /package/dist/{web → node}/rendering/camera.d.ts.map +0 -0
- /package/dist/{web → node}/rendering/projection.d.ts +0 -0
- /package/dist/{web → node}/rendering/projection.d.ts.map +0 -0
- /package/dist/{web → node}/rendering/rendering-context.d.ts +0 -0
- /package/dist/{web → node}/rendering/rendering-context.d.ts.map +0 -0
- /package/dist/{web → node}/rendering/vertex.d.ts +0 -0
- /package/dist/{web → node}/rendering/vertex.d.ts.map +0 -0
- /package/dist/{web → node}/scene/scene.d.ts +0 -0
- /package/dist/{web → node}/scene/scene.d.ts.map +0 -0
package/README.md
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
# Bloody Engine
|
|
2
2
|
|
|
3
|
-
A WebGL-based 2.5D graphics engine for isometric rendering, written in TypeScript. Designed for
|
|
3
|
+
A WebGL-based 2.5D graphics engine for isometric rendering on Node.js, written in TypeScript. Designed for server-side rendering and headless graphics processing.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
7
|
- **2.5D Rendering** - Optimized for isometric and dimetric projections
|
|
8
|
-
- **
|
|
8
|
+
- **Server-Side Rendering** - Headless WebGL rendering on Node.js using `gl` and `@kmamal/sdl`
|
|
9
9
|
- **Batch Rendering** - Efficient sprite batching with GPU-accelerated transformations
|
|
10
10
|
- **Resource Management** - Unified asset loading pipeline for textures and resources
|
|
11
11
|
- **TypeScript** - Fully typed for excellent developer experience
|
|
12
12
|
- **Depth Sorting** - Proper 2.5D occlusion handling
|
|
13
|
+
- **Window Management** - SDL-based window creation for interactive applications
|
|
13
14
|
|
|
14
15
|
## Installation
|
|
15
16
|
|
|
@@ -19,49 +20,59 @@ npm install bloody-engine
|
|
|
19
20
|
|
|
20
21
|
## Quick Start
|
|
21
22
|
|
|
22
|
-
### Browser
|
|
23
|
-
|
|
24
23
|
```typescript
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
//
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
//
|
|
34
|
-
|
|
35
|
-
|
|
24
|
+
import { GraphicsDevice, Shader, Texture } from 'bloody-engine';
|
|
25
|
+
|
|
26
|
+
// Create a graphics device with SDL window
|
|
27
|
+
const device = new GraphicsDevice(800, 600);
|
|
28
|
+
|
|
29
|
+
// Get the WebGL context
|
|
30
|
+
const gl = device.getGLContext();
|
|
31
|
+
|
|
32
|
+
// Create a shader
|
|
33
|
+
const shader = device.createShader(`
|
|
34
|
+
attribute vec3 aPosition;
|
|
35
|
+
uniform mat4 uMatrix;
|
|
36
|
+
|
|
37
|
+
void main() {
|
|
38
|
+
gl_Position = uMatrix * vec4(aPosition, 1.0);
|
|
39
|
+
}
|
|
40
|
+
`, `
|
|
41
|
+
precision mediump float;
|
|
42
|
+
uniform vec3 uColor;
|
|
43
|
+
|
|
44
|
+
void main() {
|
|
45
|
+
gl_FragColor = vec4(uColor, 1.0);
|
|
46
|
+
}
|
|
47
|
+
`);
|
|
48
|
+
|
|
49
|
+
// Create a texture from PNG
|
|
50
|
+
const { PNG } = require('pngjs');
|
|
51
|
+
const fs = require('fs/promises');
|
|
52
|
+
const pngData = await fs.readFile('texture.png');
|
|
53
|
+
const png = PNG.sync.read(pngData);
|
|
54
|
+
const texture = Texture.createFromPNG(gl, png);
|
|
36
55
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
headless: true
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
// Render and capture output
|
|
50
|
-
engine.renderFrame();
|
|
51
|
-
const pixels = engine.getPixels();
|
|
56
|
+
// Render
|
|
57
|
+
device.clear({ r: 0.1, g: 0.1, b: 0.1, a: 1.0 });
|
|
58
|
+
shader.use();
|
|
59
|
+
// ... rendering code ...
|
|
60
|
+
device.present();
|
|
61
|
+
|
|
62
|
+
// For headless rendering, capture the output
|
|
63
|
+
const context = device.getRenderingContext();
|
|
64
|
+
const pixels = context.readPixels();
|
|
52
65
|
```
|
|
53
66
|
|
|
54
|
-
## Documentation
|
|
55
|
-
|
|
56
|
-
For detailed documentation and architecture, see [docs/README.MD](docs/README.MD).
|
|
57
|
-
|
|
58
67
|
## Examples
|
|
59
68
|
|
|
69
|
+
### Sprite Batch Rendering
|
|
70
|
+
|
|
60
71
|
```typescript
|
|
61
|
-
|
|
62
|
-
import { SpriteBatchRenderer, Texture } from 'bloody-engine';
|
|
72
|
+
import { SpriteBatchRenderer, Camera, Texture } from 'bloody-engine';
|
|
63
73
|
|
|
64
|
-
const batchRenderer = new SpriteBatchRenderer(gl, shader);
|
|
74
|
+
const batchRenderer = new SpriteBatchRenderer(gl, shader, 1000);
|
|
75
|
+
const camera = new Camera(0, 0, 1.0);
|
|
65
76
|
|
|
66
77
|
// Add sprites
|
|
67
78
|
batchRenderer.addQuad({
|
|
@@ -79,6 +90,43 @@ batchRenderer.addQuad({
|
|
|
79
90
|
batchRenderer.render(camera);
|
|
80
91
|
```
|
|
81
92
|
|
|
93
|
+
### Resource Loading
|
|
94
|
+
|
|
95
|
+
```typescript
|
|
96
|
+
import { NodeResourceLoader } from 'bloody-engine';
|
|
97
|
+
|
|
98
|
+
const loader = new NodeResourceLoader('./assets');
|
|
99
|
+
|
|
100
|
+
// Load a shader
|
|
101
|
+
const vertexSource = await loader.load('shaders/basic.vert');
|
|
102
|
+
const fragmentSource = await loader.load('shaders/basic.frag');
|
|
103
|
+
|
|
104
|
+
// Batch load multiple resources
|
|
105
|
+
const { succeeded, failed } = await loader.loadMultiple([
|
|
106
|
+
'textures/sprite1.png',
|
|
107
|
+
'textures/sprite2.png',
|
|
108
|
+
'shaders/shader.vert'
|
|
109
|
+
]);
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Dependencies
|
|
113
|
+
|
|
114
|
+
- **gl** - Headless WebGL for Node.js
|
|
115
|
+
- **@kmamal/sdl** - SDL2 bindings for window and input management
|
|
116
|
+
- **pngjs** - PNG image decoding
|
|
117
|
+
|
|
118
|
+
## Documentation
|
|
119
|
+
|
|
120
|
+
For detailed documentation and architecture, see [docs/README.MD](docs/README.MD).
|
|
121
|
+
|
|
122
|
+
## Building
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
npm run build
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
This will generate the distribution files in `dist/node/`.
|
|
129
|
+
|
|
82
130
|
## License
|
|
83
131
|
|
|
84
132
|
MIT License - see [LICENSE](LICENSE) for details.
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { IResourceLoader } from './resource-loader';
|
|
2
|
+
/**
|
|
3
|
+
* Environment type enumeration
|
|
4
|
+
*/
|
|
5
|
+
export declare enum Environment {
|
|
6
|
+
/** Node.js environment (file system APIs available) */
|
|
7
|
+
NODE = "node"
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Resource loader factory configuration
|
|
11
|
+
*/
|
|
12
|
+
export interface ResourceLoaderFactoryOptions {
|
|
13
|
+
/**
|
|
14
|
+
* Base directory for Node.js resource loader
|
|
15
|
+
*/
|
|
16
|
+
baseDir?: string;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Factory class for creating resource loaders
|
|
20
|
+
* Creates Node.js resource loaders
|
|
21
|
+
*/
|
|
22
|
+
export declare class ResourceLoaderFactory {
|
|
23
|
+
/**
|
|
24
|
+
* Detect the current runtime environment
|
|
25
|
+
* @returns The detected environment type (always NODE)
|
|
26
|
+
*/
|
|
27
|
+
static detectEnvironment(): Environment;
|
|
28
|
+
/**
|
|
29
|
+
* Check if the current environment is a browser
|
|
30
|
+
* @returns false (not browser)
|
|
31
|
+
*/
|
|
32
|
+
static isBrowser(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Check if the current environment is Node.js
|
|
35
|
+
* @returns true
|
|
36
|
+
*/
|
|
37
|
+
static isNode(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Create a Node.js resource loader
|
|
40
|
+
* @param options Optional factory configuration
|
|
41
|
+
* @returns A Node.js resource loader instance
|
|
42
|
+
*/
|
|
43
|
+
static create(options?: ResourceLoaderFactoryOptions): Promise<IResourceLoader>;
|
|
44
|
+
/**
|
|
45
|
+
* Create a Node.js resource loader
|
|
46
|
+
* @param options Optional factory configuration
|
|
47
|
+
* @returns A Node.js resource loader instance
|
|
48
|
+
*/
|
|
49
|
+
static createNodeLoader(options?: ResourceLoaderFactoryOptions): Promise<IResourceLoader>;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Convenience function to create a resource loader
|
|
53
|
+
* Shortcut for ResourceLoaderFactory.create()
|
|
54
|
+
* @param options Optional factory configuration
|
|
55
|
+
* @returns A resource loader instance
|
|
56
|
+
*/
|
|
57
|
+
export declare function createResourceLoader(options?: ResourceLoaderFactoryOptions): Promise<IResourceLoader>;
|
|
58
|
+
//# sourceMappingURL=resource-loader-factory.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resource-loader-factory.d.ts","sourceRoot":"","sources":["../../../src/core/resource-loader-factory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAGzD;;GAEG;AACH,oBAAY,WAAW;IACrB,uDAAuD;IACvD,IAAI,SAAS;CACd;AAED;;GAEG;AACH,MAAM,WAAW,4BAA4B;IAC3C;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,qBAAa,qBAAqB;IAChC;;;OAGG;IACH,MAAM,CAAC,iBAAiB,IAAI,WAAW;IAIvC;;;OAGG;IACH,MAAM,CAAC,SAAS,IAAI,OAAO;IAI3B;;;OAGG;IACH,MAAM,CAAC,MAAM,IAAI,OAAO;IAIxB;;;;OAIG;WACU,MAAM,CAAC,OAAO,CAAC,EAAE,4BAA4B,GAAG,OAAO,CAAC,eAAe,CAAC;IAIrF;;;;OAIG;WACU,gBAAgB,CAC3B,OAAO,CAAC,EAAE,4BAA4B,GACrC,OAAO,CAAC,eAAe,CAAC;CAG5B;AAED;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACxC,OAAO,CAAC,EAAE,4BAA4B,GACrC,OAAO,CAAC,eAAe,CAAC,CAE1B"}
|
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KAAK,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,MAAM,CAAC;QACf,QAAQ,EAAE,MAAM,CAAC;KAClB,CAAC,EACF,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,iBAAiB,EAAE,CAAC;IAkB/B;;;;;OAKG;IACG,gBAAgB,CACpB,YAAY,EAAE,MAAM,EACpB,OAAO,CAAC,EAAE,mBAAmB,GAC5B,OAAO,CAAC,eAAe,CAAC;IAS3B;;;;;OAKG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,mBAAmB,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5E;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAI/B;;;;OAIG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAI3C;;OAEG;IACH,UAAU,IAAI,IAAI;IAIlB;;;OAGG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,WAAW,IAAI,IAAI;IAInB;;OAEG;IACH,YAAY,IAAI,IAAI;IAIpB;;;OAGG;IACH,cAAc,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAIzC;;;OAGG;IACH,SAAS,IAAI,eAAe;CAG7B;AAED;;;;GAIG;AACH,wBAAsB,sBAAsB,CAC1C,OAAO,CAAC,EAAE,uBAAuB,GAAG;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,GACA,OAAO,CAAC,gBAAgB,CAAC,CAS3B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resource-loader-demo.d.ts","sourceRoot":"","sources":["../../../src/examples/resource-loader-demo.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAyCH;;GAEG;AACH,wBAAsB,4BAA4B,IAAI,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"resource-loader-demo.d.ts","sourceRoot":"","sources":["../../../src/examples/resource-loader-demo.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAyCH;;GAEG;AACH,wBAAsB,4BAA4B,IAAI,OAAO,CAAC,IAAI,CAAC,CA+QlE"}
|