@nativescript/canvas-three 2.0.0-webgpu.9 → 2.0.1
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 +50 -19
- package/index.d.ts +2 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -9,14 +9,47 @@ npm i three @nativescript/canvas-three
|
|
|
9
9
|
## Usage
|
|
10
10
|
|
|
11
11
|
```js
|
|
12
|
-
import
|
|
12
|
+
import * as THREE from '@nativescript/canvas-three';
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## Creating a Renderer
|
|
16
16
|
|
|
17
|
-
####
|
|
17
|
+
#### Using WebGPU
|
|
18
18
|
|
|
19
|
-
|
|
19
|
+
Add the following to the webpackconfig.js
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
const webpack = require('@nativescript/webpack');
|
|
23
|
+
const { resolve } = require('path');
|
|
24
|
+
|
|
25
|
+
module.exports = (env) => {
|
|
26
|
+
....
|
|
27
|
+
/// the path depends on the location of node_modules in this example it's in the root of the plugin repo in a simple project it would be './node_modules/three/build.three.webgpu.js' and not '../../node_modules/three/build.three.webgpu.js'
|
|
28
|
+
webpack.chainWebpack((config) => {
|
|
29
|
+
config.resolve.alias.set('three', resolve(__dirname, '..', '..', 'node_modules', 'three', 'build', 'three.webgpu.js'));
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```ts
|
|
34
|
+
const renderer = new THREE.WebGPURenderer({ canvas, antialias: false });
|
|
35
|
+
renderer.setPixelRatio(window.devicePixelRatio);
|
|
36
|
+
renderer.setSize(canvas.clientWidth, canvas.clientHeight, false);
|
|
37
|
+
await renderer.init();
|
|
38
|
+
// grab the webgpu context as it's needed to present/render to the screen this is currently needed for now until it's removed in the future
|
|
39
|
+
const context = canvas.getContext('webgpu');
|
|
40
|
+
/// at the end of your render loop add the following
|
|
41
|
+
// context.presentSurface();
|
|
42
|
+
// e.g
|
|
43
|
+
|
|
44
|
+
function render() {
|
|
45
|
+
renderer.render(scene, camera);
|
|
46
|
+
context.presentSurface();
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
####
|
|
51
|
+
|
|
52
|
+
Given a `gl (context)` from a
|
|
20
53
|
[`Canvas`](https://github.com/nativescript/canvas), return a
|
|
21
54
|
[`THREE.WebGLRenderer`](https://threejs.org/docs/#api/renderers/WebGLRenderer)
|
|
22
55
|
that draws into it.
|
|
@@ -32,31 +65,29 @@ init();
|
|
|
32
65
|
animate();
|
|
33
66
|
|
|
34
67
|
function init() {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const { drawingBufferWidth: width, drawingBufferHeight: height } = context;
|
|
38
|
-
camera = new THREE.PerspectiveCamera(70, width / height, 0.01, 10);
|
|
39
|
-
camera.position.z = 1;
|
|
68
|
+
camera = new THREE.PerspectiveCamera(70, canvas.clientWidth / canvas.clientHeight, 0.01, 10);
|
|
69
|
+
camera.position.z = 1;
|
|
40
70
|
|
|
41
|
-
|
|
71
|
+
scene = new THREE.Scene();
|
|
42
72
|
|
|
43
|
-
|
|
44
|
-
|
|
73
|
+
geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
|
|
74
|
+
material = new THREE.MeshNormalMaterial();
|
|
45
75
|
|
|
46
|
-
|
|
47
|
-
|
|
76
|
+
mesh = new THREE.Mesh(geometry, material);
|
|
77
|
+
scene.add(mesh);
|
|
48
78
|
|
|
49
|
-
|
|
50
|
-
|
|
79
|
+
const renderer = new THREE.WebGLRenderer({ canvas, antialias: false });
|
|
80
|
+
renderer.setPixelRatio(window.devicePixelRatio);
|
|
81
|
+
renderer.setSize(canvas.clientWidth, canvas.clientHeight, false);
|
|
51
82
|
}
|
|
52
83
|
|
|
53
84
|
function animate() {
|
|
54
|
-
|
|
85
|
+
requestAnimationFrame(animate);
|
|
55
86
|
|
|
56
|
-
|
|
57
|
-
|
|
87
|
+
mesh.rotation.x += 0.01;
|
|
88
|
+
mesh.rotation.y += 0.02;
|
|
58
89
|
|
|
59
|
-
|
|
90
|
+
renderer.render(scene, camera);
|
|
60
91
|
}
|
|
61
92
|
```
|
|
62
93
|
|
package/index.d.ts
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import '@nativescript/canvas-polyfill';
|
|
2
|
+
export * from 'three';
|
package/index.js
CHANGED
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/canvas-three/index.ts"],"names":[],"mappings":"AACA,OAAO
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../packages/canvas-three/index.ts"],"names":[],"mappings":"AACA,OAAO,+BAA+B,CAAC;AACvC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC9B,MAAc,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;AACpE,cAAc,OAAO,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nativescript/canvas-three",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Utilities for using THREE.js on NativeScript",
|
|
5
5
|
"main": "index",
|
|
6
6
|
"typings": "index.d.ts",
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"readmeFilename": "README.md",
|
|
34
34
|
"bootstrapper": "@nativescript/plugin-seed",
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@nativescript/canvas-polyfill": "
|
|
37
|
-
"three": "~0.
|
|
36
|
+
"@nativescript/canvas-polyfill": "*",
|
|
37
|
+
"three": "~0.169.0"
|
|
38
38
|
},
|
|
39
39
|
"types": "./index.d.ts"
|
|
40
40
|
}
|