npm i --save nativescript-three
- 版本: 1.0.0-alpha3
- GitHub: https://github.com/triniwiz/nativescript-three
- NPM: https://npmjs.net.cn/package/nativescript-three
- 下载
- 昨日: 0
- 上周: 0
- 上月: 0
nativescript-three
安装
npm i three nativescript-three
用法
import TNSTHREE from 'nativescript-three';
创建渲染器
TNSTHREE.Renderer({ gl: WebGLRenderingContext, width: number, height: number, pixelRatio: number, ...extras })
给定一个来自 TNSCanvas
的 gl (上下文)
,返回一个 THREE.WebGLRenderer
,它将绘制到其中。
import { Renderer } from 'nativescript-three';
var camera, scene, renderer;
var geometry, material, mesh;
canvas; // TNSCanvas instance
init();
animate();
function init() {
const gl = canvas.getContext('webgl');
// We have access to window.innerWidth / window.innerHeight but we want the current view size
const { drawingBufferWidth: width, drawingBufferHeight: height } = gl;
camera = new THREE.PerspectiveCamera(70, width / height, 0.01, 10);
camera.position.z = 1;
scene = new THREE.Scene();
geometry = new THREE.BoxGeometry(0.2, 0.2, 0.2);
material = new THREE.MeshNormalMaterial();
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
renderer = new TNSTHREE.Renderer({ gl });
renderer.setSize(width, height);
}
function animate() {
requestAnimationFrame(animate);
mesh.rotation.x += 0.01;
mesh.rotation.y += 0.02;
renderer.render(scene, camera);
canvas.flush(); // very important, call when you need to render to screen.
}
例如输出
例如输出
许可协议
Apache 许可协议版本 2.0,2004 年 1 月