Skip to content

Commit 1b470ac

Browse files
committed
Update examples
1 parent 79f049b commit 1b470ac

File tree

10 files changed

+44
-48
lines changed

10 files changed

+44
-48
lines changed

README.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ See [TS declarations](/index.d.ts) for more details.
4040

4141
```javascript
4242
import * as THREE from 'three';
43+
4344
import node3d from '../index.js';
4445
const { init, addThreeHelpers } = node3d;
4546

@@ -56,10 +57,9 @@ const material = new THREE.MeshBasicMaterial({ map: texture });
5657
const mesh = new THREE.Mesh(geometry, material);
5758
screen.scene.add(mesh);
5859

59-
loop(() => {
60-
const time = Date.now();
61-
mesh.rotation.x = time * 0.0005;
62-
mesh.rotation.y = time * 0.001;
60+
loop((now) => {
61+
mesh.rotation.x = now * 0.0005;
62+
mesh.rotation.y = now * 0.001;
6363
screen.draw();
6464
});
6565
```
@@ -79,25 +79,25 @@ Example Notes:
7979

8080
## OpenGL Features
8181

82-
1. This is real native OpenGL, and you have direct access to GL resource IDs. This may be
82+
1. This is real **native OpenGL**, and you have direct access to GL resource IDs. This may be
8383
useful for resource sharing and compute interop (such as
8484
[CUDA-GL interop](https://docs.nvidia.com/cuda/cuda-runtime-api/group__CUDART__OPENGL.html)).
85-
1. The flag `isGles3` let's you use a GL ES 3 preset, which is closest to "real" WebGL.
85+
1. The flag `isGles3` lets you use a **GL ES 3** preset, which is closest to "real" WebGL.
8686
If set to `false`, WebGL stuff (such as three.js) will still work, but now with some hacks.
87-
However, if you are planning to use non-WebGL features (e.g. OpenGL 4.5 features),
87+
However, if you are planning to use non-WebGL features (e.g. **OpenGL 4.5** features),
8888
you might want it off, and then select a specific context version manually.
8989
1. The flag `isWebGL2` impacts how web libraries recognize the WebGL version.
9090
But it doesn't really change the capabilities of the engine.
91-
1. Offscreen rendering is possible on Windows and Linux, as demonstrated by the tests
91+
1. **Offscreen rendering** is possible on Windows and Linux, as demonstrated by the tests
9292
running in GitHub Actions. There are test cases that generate and compare screenshots,
9393
and they do work in headless mode.
94-
1. OpenGL context sharing is enabled. You can obtain `HDC, HWND, CTX` for Windows and whatever
94+
1. OpenGL **context sharing** is enabled. You can obtain `HDC, HWND, CTX` for Windows and whatever
9595
those are called on Linux and MacOS. See [glfw-raub](https://github.com/node-3d/glfw-raub).
9696

9797

9898
## License
9999

100-
You get this for free. Have fun!
100+
**You get this for free. Have fun!**
101101

102102
Some of the components have their separate licenses, but all of them may be used
103103
commercially, without royalty.

examples/3d-core/mesh.mjs

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ pointLight.position.y = 20;
3535
pointLight.position.z = 5;
3636

3737

38-
loop(() => {
39-
mesh.rotation.x = Date.now() * 0.0005;
40-
mesh.rotation.y = Date.now() * 0.001;
41-
mesh.rotation.z = Date.now() * 0.0007;
38+
loop((now) => {
39+
mesh.rotation.x = now * 0.0005;
40+
mesh.rotation.y = now * 0.001;
41+
mesh.rotation.z = now * 0.0007;
4242
screen.draw();
4343
});

examples/crate-lean.mjs

+3-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import * as THREE from 'three';
33
import node3d from '../index.js';
44
const { init, addThreeHelpers } = node3d;
55

6-
76
const { gl, loop, Screen } = init({
87
isGles3: true, vsync: true, autoEsc: true, autoFullscreen: true, title: 'Crate',
98
});
@@ -17,9 +16,8 @@ const material = new THREE.MeshBasicMaterial({ map: texture });
1716
const mesh = new THREE.Mesh(geometry, material);
1817
screen.scene.add(mesh);
1918

20-
loop(() => {
21-
const time = Date.now();
22-
mesh.rotation.x = time * 0.0005;
23-
mesh.rotation.y = time * 0.001;
19+
loop((now) => {
20+
mesh.rotation.x = now * 0.0005;
21+
mesh.rotation.y = now * 0.001;
2422
screen.draw();
2523
});

examples/knot.mjs

+3-4
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ const outlineMesh = new THREE.Mesh(outlineGeometry, outlineMaterial);
3838
knotMesh.add(outlineMesh);
3939

4040
// Called repeatedly to render new frames
41-
loop(() => {
42-
const time = Date.now();
43-
knotMesh.rotation.x = time * 0.0005;
44-
knotMesh.rotation.y = time * 0.001;
41+
loop((now) => {
42+
knotMesh.rotation.x = now * 0.0005;
43+
knotMesh.rotation.y = now * 0.001;
4544
screen.draw();
4645
});

examples/palette/palette.mjs

+5-6
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,11 @@ const render = () => {
211211
let prevTime = Date.now();
212212
let frames = 0;
213213

214-
loop(() => {
214+
loop((now) => {
215215
controls.update();
216216

217217
if (mesh) {
218-
mesh.rotation.y = Date.now() * 0.00005;
218+
mesh.rotation.y = now * 0.00005;
219219
}
220220

221221
render();
@@ -225,12 +225,11 @@ loop(() => {
225225
}
226226

227227
frames++;
228-
const time = Date.now();
229-
if (time >= prevTime + 2000) {
228+
if (now >= prevTime + 2000) {
230229
console.log(
231-
'FPS:', Math.floor((frames * 1000) / (time - prevTime)),
230+
'FPS:', Math.floor((frames * 1000) / (now - prevTime)),
232231
);
233-
prevTime = time;
232+
prevTime = now;
234233
frames = 0;
235234
}
236235
});

examples/srgb/main.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55

66
import Img from 'image-raub';
77
import { init } from '3d-core-raub';
8-
import { SimpleTextureProcessor } from './simple_texture_processor';
8+
import { SimpleTextureProcessor } from './simple_texture_processor.ts';
99

1010
init({
1111
isGles3: true,

examples/srgb/tsconfig.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@
99
},
1010
"target": "es2017",
1111
"moduleResolution": "nodenext",
12-
"module": "nodenext",
12+
"module": "NodeNext",
1313
"allowJs": true,
1414
"esModuleInterop": true,
1515
"allowSyntheticDefaultImports": true,
16+
"allowImportingTsExtensions": true,
1617
"forceConsistentCasingInFileNames": true,
1718
"strict": true,
1819
"noEmit": true,

examples/three/post.mjs

+5-6
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,8 @@ function createMesh(geometry, scene, scale) {
316316
let prevTime = Date.now();
317317
let frames = 0;
318318

319-
loop(() => {
320-
const timedRotation = Date.now() * 0.0004;
319+
loop((now) => {
320+
const timedRotation = now * 0.0004;
321321

322322
if (mesh) mesh.rotation.y = -timedRotation;
323323

@@ -341,12 +341,11 @@ loop(() => {
341341
}
342342

343343
frames++;
344-
const time = Date.now();
345-
if (time >= prevTime + 1000) {
344+
if (now >= prevTime + 2000) {
346345
console.log(
347-
'FPS:', Math.floor((frames * 1000) / (time - prevTime)),
346+
'FPS:', Math.floor((frames * 1000) / (now - prevTime)),
348347
);
349-
prevTime = time;
348+
prevTime = now;
350349
frames = 0;
351350
}
352351
});

package-lock.json

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"addon-tools-raub": "^9.3.0",
4141
"image-raub": "^5.2.0",
4242
"glfw-raub": "^6.4.0",
43-
"webgl-raub": "^5.2.0"
43+
"webgl-raub": "^5.3.0"
4444
},
4545
"devDependencies": {
4646
"@types/node": "^22.13.4",

0 commit comments

Comments
 (0)