@nativescript/canvas-three
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@nativescript/canvas-three

Installation

npm i three @nativescript/canvas-three

Usage

import TNSTHREE from '@nativescript/canvas-three';

Creating a Renderer

TNSTHREE.Renderer({ gl: WebGLRenderingContext, width: number, height: number, pixelRatio: number, ...extras })

Given a gl (context) from an Canvas, return a THREE.WebGLRenderer that draws into it.

import * as THREE from 'three';

var camera, scene, renderer;
var geometry, material, mesh;

canvas; // Canvas instance
init();
animate();

function init() {
  const context = canvas.getContext('webgl');

  const { drawingBufferWidth: width, drawingBufferHeight: height } = context;
  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 THREE.WebGLRenderer({ context });
  renderer.setSize(width, height);
}

function animate() {
  requestAnimationFrame(animate);

  mesh.rotation.x += 0.01;
  mesh.rotation.y += 0.02;

  renderer.render(scene, camera);
}

License

Apache License Version 2.0, January 2004

/@nativescript/canvas-three/

    Package Sidebar

    Install

    npm i @nativescript/canvas-three

    Weekly Downloads

    22

    Version

    1.1.0

    License

    Apache-2.0

    Unpacked Size

    14.2 kB

    Total Files

    6

    Last publish

    Collaborators

    • mukaschultze
    • nativescript-user
    • tns-bot
    • lini
    • tachev
    • rosen-vladimirov
    • stoskov
    • rosen_vladimirov
    • walkerrunpdx
    • bradmartin
    • davecoffin
    • rigor789
    • nativescript-bot
    • multishiv19
    • eddyverbruggen
    • edusperoni
    • facetious
    • tdermendjiev
    • sis0k0