npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

three-fspy-camera-loader

v2.4.2

Published

Script to import camera matching data in fSpy into three.js

Downloads

62

Readme

three-fspy-camera-loader

npm NPM Build Status

demo

demo page

What is this?

Script for importing fSpy camera data into three.js.

You can create a pseudo AR-like visual representation.

I made a demo on this page.

It takes in the json format camera data output by fSpy and converts it into the PerspetiveCamera of three.js.

three-fspy-camera-loader inherits the Loader object of three.js and can be used in the same way as other loaders.

I'm Japanese so I'm not good at English. So I'm sorry if I used the wrong English.

Installing from npm

$ npm install --save three-fspy-camera-loader

Examples

codesandbox(TypeScript)

If it doesn't work, reload.

Other examples are in preparation.

Link Collection

fSpy official website

fspy repository

fSpy video

fSpy importer addon for Blender

Getting Started

var loader = new FSpyCameraLoader();
var camera;

loader.load(
  'path/to/fSpyJsonFile',
  // onload
  function ( result ) {
    camera = result;
  },
  // onprogress
  function ( xhr ) {
    console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
  },
  // onerror
  function ( error ) {
    console.log( 'ERROR' );
  }
);

If you want to include a background image, you can use the following example. Of course, other methods are also acceptable.

html,body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
}
#myCanvas {
  width: 100%;
  height: 100%;
  background-image: url(path/to/image);
  background-size: cover;
  background-position: 50% 50%;
  background-repeat: no-repeat;
}

var camera;

var renderer = new THREE.WebGLRenderer({
  canvas: document.querySelector('#myCanvas'),
  alpha: true,
});
renderer.setPixelRatio(window.devicePixelRatio);
renderer.setClearColor(0x000000, 0);
renderer.setSize(window.innerWidth, window.innerHeight);

var scene = new THREE.Scene();
var geometry = new THREE.BoxGeometry(3, 3, 3);
var material = new THREE.MeshNormalMaterial();
var box = new THREE.Mesh(geometry, material);
box.position.set(0, 0, 0);
scene.add(box);

var fSpyCameraLoader = new FSpyCameraLoader();
fSpyCameraLoader.setCanvas(document.querySelector('#myCanvas'));
// If you want to make the behavior behave like CSS background-size: cover, use this function.
fSpyCameraLoader.setResizeUpdate();

fSpyCameraLoader.load('path/to/fSpyJson', function ( result ) {
  camera = result;
  renderLoop();
});

window.addEventListener('resize', function () {
  renderer.setSize(window.innerWidth, window.innerHeight);
});

function renderLoop() {
  requestAnimationFrame(renderLoop);
  renderer.render(scene, camera);
  box.rotation.y += 0.01;
}

Notice

json export

You can export json using fSpy from here.

export

Axis setting

When using with three.js, it is recommended that the Y-axis be up.

note

constructor

+ new FSpyCamerLoader(manager?: LoadingManager): FSpyCamerLoader

Overrides void

Defined in src/FSpyCameraLoader.ts:37

Parameters:

| Name | Type | | ---------- | -------------- | | manager? | LoadingManager |

Returns: FSpyCamerLoader

Main Properties

| Name | Type | Description | | ------------------------------------------------------------ | ------------------------------------------------------------ | :----------------------------------------------------------- | | .camera | PerspectiveCamera | PerspectiveCamera of three.js. The final result is stored on this camera. | | .dataManager | FSpyDataManager | Class that manages camera data of fSpy. Mainly used internally.more information | | .targetCanvas | HTMLCanvasElement | null | Canvas that is the target for drawing WebGL. It is mainly used for updating the camera according to the resize. | | .isEnableResizeEvent | boolean | (get) Gets whether the resize event is set.(set) Enable / disable resize event |

all properties

Main Methods

load

load(url: string, onLoad?: undefined | function, onProgress?: undefined | function, onError?: undefined | function): void

Defined in src/FSpyCameraLoader.ts:80

load fSpy's camera data json

Parameters:

| Name | Type | Description | | ------------- | ------------------------- | ------------------------------------------------------------ | | url | string | Path to camera data json to be exported by fSpy | | onLoad? | undefined | function | Function after loading | | onProgress? | undefined | function | Function being loaded. Probably not needed due to the small data size. | | onError? | undefined | function | Function when the error occurred TODO: IE |

Returns: void


loadAsync

loadAsync(url: string, onProgress?: undefined | function): Promise‹any›

Defined in node_modules/three/src/loaders/Loader.d.ts:20

Parameters:

| Name | Type | Description | | ------------- | ------------------------- | ------------------------------------------------------------ | | url | string | Path to camera data json to be exported by fSpy | | onProgress? | undefined | function | Function being loaded. Probably not needed due to the small data size. |

Returns: Promise‹any›


parse

parse(fSpyJson: FSpyCameraJson): PerspectiveCamera

Defined in src/FSpyCameraLoader.ts:115

Parses fSpy json data. This function is also called after the load function.

Parameters:

| Name | Type | Description | | ---------- | ------------------------------------------------------------ | ------------------------------------------------------------ | | fSpyJson | FSpyCameraJson | json data from fSpy. Please put the parsed one, such as JSON.parse (json) ;. |

Returns: PerspectiveCamera

Camera using fSpy camera data


getComputedData

getComputedData(): FSpyCameraData | null

Defined in src/FSpyCameraLoader.ts:227

Get camera data processed for three.js

Returns: FSpyCameraData | null

json data from fSpy converted to data for three.js


getData

getData(): FSpyCameraJson | null

Defined in src/FSpyCameraLoader.ts:219

Get unprocessed internal camera data

Returns: FSpyCameraJson | null

json data output from fSpy


onResize

onResize(): void

Defined in src/FSpyCameraLoader.ts:195

Change the camera data according to the size of the canvas to render.

Returns: void


setCanvas

setCanvas(canvas: HTMLCanvasElement): void

Defined in src/FSpyCameraLoader.ts:124

Add the data for the canvas element for the library to know.

Parameters:

| Name | Type | Description | | -------- | ----------------- | ------------------------------------------- | | canvas | HTMLCanvasElement | Canvas that is the target for drawing WebGL |

Returns: void


removeCanvas

removeCanvas(): void

Defined in src/FSpyCameraLoader.ts:131

Remove the data for the canvas element.

Returns: void


setResizeUpdate

setResizeUpdate(): void

Defined in src/FSpyCameraLoader.ts:138

Enables the ability to change the camera data according to the size of the canvas to render.

Returns: void


removeResizeupdate

removeResizeupdate(): void

Defined in src/FSpyCameraLoader.ts:145

Disables the ability to change camera data to fit the size of the canvas to render.

Returns: void


all methods

API documentation

Please see here.

LISENCE

MIT