@footgun/cobalt 0.3.0 → 0.3.2
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.
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import * as Cobalt from '../../bundle.js'
|
|
2
|
+
import sdl from '@kmamal/sdl'
|
|
3
|
+
import gpu from '@kmamal/gpu'
|
|
4
|
+
import { vec2 } from 'wgpu-matrix'
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
async function main () {
|
|
8
|
+
const width = 480
|
|
9
|
+
const height = 340
|
|
10
|
+
|
|
11
|
+
const window = sdl.video.createWindow({ webgpu: true, width, height/*, borderless: true*/ })
|
|
12
|
+
|
|
13
|
+
window.setTitle('examples/09-sdl-polar-meters')
|
|
14
|
+
|
|
15
|
+
const c = await Cobalt.init({ sdlWindow: window, gpu }, width, height)
|
|
16
|
+
|
|
17
|
+
const pNode = await Cobalt.initNode(c, {
|
|
18
|
+
type: 'cobalt:primitives',
|
|
19
|
+
refs: {
|
|
20
|
+
// key is the var name defined in this node
|
|
21
|
+
// value is the var name in the cobalt resources dictionary
|
|
22
|
+
color: 'FRAME_TEXTURE_VIEW',
|
|
23
|
+
},
|
|
24
|
+
options: { }
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const gameLoop = function () {
|
|
28
|
+
|
|
29
|
+
const z = 16.0
|
|
30
|
+
|
|
31
|
+
c.viewport.zoom = z // pixels per meter
|
|
32
|
+
|
|
33
|
+
Cobalt.setViewportDimensions(c, width, height)
|
|
34
|
+
Cobalt.setViewportPosition(c, [ 1, -16 ])
|
|
35
|
+
//Cobalt.setViewportPosition(c, [ 240, 170 ])
|
|
36
|
+
|
|
37
|
+
pNode.clear()
|
|
38
|
+
|
|
39
|
+
//pNode.filledBox([ 240, 170 ], 480/z, 340/z, [ 0, 1, 0, 1 ])
|
|
40
|
+
pNode.filledBox([ 1, -16 ], 1.0, 2.0, [ 0, 1, 0, 1 ])
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
Cobalt.draw(c)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
gameLoop()
|
|
47
|
+
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
main()
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "09-sd-polar-meters",
|
|
3
|
+
"private": true,
|
|
4
|
+
"type": "module",
|
|
5
|
+
"version": "1.0.0",
|
|
6
|
+
"description": "test module using sdl + gpu + cobalt",
|
|
7
|
+
"main": "main.js",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
+
},
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "ISC",
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@kmamal/gpu": "^0.1.3",
|
|
15
|
+
"@kmamal/sdl": "^0.10.2",
|
|
16
|
+
"pngjs": "^7.0.0",
|
|
17
|
+
"wgpu-matrix": "^3.0.2"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/package.json
CHANGED
|
@@ -235,8 +235,10 @@ function _writeMatricesBuffer (cobalt, node) {
|
|
|
235
235
|
// left right bottom top near far
|
|
236
236
|
const projection = mat4.ortho(0, GAME_WIDTH, GAME_HEIGHT, 0, -10.0, 10.0)
|
|
237
237
|
|
|
238
|
-
|
|
239
|
-
|
|
238
|
+
// TODO: 1.0 must be subtracted from both x and y values otherwise everything get shifted down and to the right
|
|
239
|
+
// when rendered. This is true for both sdl and browser backed rendering. I don't understand why though!!
|
|
240
|
+
vec3.set(-cobalt.viewport.position[0] - 1.0, -cobalt.viewport.position[1] - 1.0 , 0, _tmpVec3)
|
|
241
|
+
|
|
240
242
|
const view = mat4.translation(_tmpVec3)
|
|
241
243
|
|
|
242
244
|
device.queue.writeBuffer(node.data.uniformBuffer, 0, view.buffer)
|
|
@@ -40,18 +40,9 @@ export default {
|
|
|
40
40
|
|
|
41
41
|
filledPath: function (cobalt, node, points, color) {
|
|
42
42
|
|
|
43
|
-
const edges = [ ]
|
|
44
|
-
|
|
45
|
-
for (let i=1; i < points.length; i++)
|
|
46
|
-
edges.push([ i-1, i ])
|
|
47
|
-
|
|
48
43
|
const pslg = poly2pslg(points)
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// The flag {exterior: false} tells it to remove exterior faces
|
|
52
|
-
//const triangles = cdt2d(points, edges, { exterior: true })
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
// The flag { exterior: false } tells it to remove exterior faces
|
|
45
|
+
const triangles = cdt2d(pslg.points, pslg.edges, { exterior: false })
|
|
55
46
|
|
|
56
47
|
const m = node.data.transforms.at(-1)
|
|
57
48
|
|