All Projects → vasturiano → three-render-objects

vasturiano / three-render-objects

Licence: MIT license
Easy way to render ThreeJS objects with built-in interaction defaults

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to three-render-objects

Jeelizfacefilter
Javascript/WebGL lightweight face tracking library designed for augmented reality webcam filters. Features : multiple faces detection, rotation, mouth opening. Various integration examples are provided (Three.js, Babylon.js, FaceSwap, Canvas2D, CSS3D...).
Stars: ✭ 2,042 (+6087.88%)
Mutual labels:  threejs, camera
ShadowEditor-examples
ShadowEditor Demo. https://tengge1.github.io/ShadowEditor-examples/
Stars: ✭ 33 (+0%)
Mutual labels:  threejs, scene
three-orbitcontrols
is the three.js OrbitControls from official repo examples
Stars: ✭ 80 (+142.42%)
Mutual labels:  threejs, camera
Lume
Create CSS3D/WebGL applications declaratively with HTML. Give regular DOM elements shadow and lighting.
Stars: ✭ 445 (+1248.48%)
Mutual labels:  threejs, scene
Snapchat Clone
👻 A SnapChat clone built with React, Redux and Typescript. Styled with SASS. Tested with Cypress, Jest and Enzyme. Linted with Eslint and formatted with Prettier!
Stars: ✭ 770 (+2233.33%)
Mutual labels:  threejs, camera
Camera Controls
A camera control for three.js, similar to THREE.OrbitControls yet supports smooth transitions and more features.
Stars: ✭ 519 (+1472.73%)
Mutual labels:  threejs, camera
Three.terrain
A procedural terrain generation engine for use with the Three.js 3D graphics library for the web.
Stars: ✭ 353 (+969.7%)
Mutual labels:  threejs, scene
Shadoweditor
Cross-platform 3D scene editor based on three.js, golang and mongodb for desktop and web. https://tengge1.github.io/ShadowEditor-examples/
Stars: ✭ 1,060 (+3112.12%)
Mutual labels:  threejs, scene
Patches
Patches is a visual programming editor for building WebVR and WebGL experiences.
Stars: ✭ 164 (+396.97%)
Mutual labels:  threejs, camera
asset-mix
Provides helpers functions for CakePHP to use Laravel Mix.
Stars: ✭ 27 (-18.18%)
Mutual labels:  scaffolding
three-noise
Simple gradient noise library for use with Three.js. Now with fBm!
Stars: ✭ 31 (-6.06%)
Mutual labels:  threejs
redundans
Redundans is a pipeline that assists an assembly of heterozygous/polymorphic genomes.
Stars: ✭ 90 (+172.73%)
Mutual labels:  scaffolding
apate-ar
Framwork for environment aware AR with occlusion, lighting PBR rendering, physics support (cannon.js), based on three.js
Stars: ✭ 77 (+133.33%)
Mutual labels:  threejs
react-translations-provider
React render props component for setting translations
Stars: ✭ 35 (+6.06%)
Mutual labels:  render
three-font-outliner
Constructing shapes from glyphs at runtime for three.js.
Stars: ✭ 58 (+75.76%)
Mutual labels:  threejs
godot-trackball-camera
A short Godot addon that adds a TrackballCamera node without gimbal lock.
Stars: ✭ 22 (-33.33%)
Mutual labels:  camera
opencart-project-template
OpenCart Project Template
Stars: ✭ 16 (-51.52%)
Mutual labels:  scaffolding
virtex
A three.js object viewer written in TypeScript
Stars: ✭ 14 (-57.58%)
Mutual labels:  threejs
sensorr
🍿📼 Sensorr - Your Friendly Digital Video Recorder
Stars: ✭ 90 (+172.73%)
Mutual labels:  scene
billiards
billiards physics
Stars: ✭ 37 (+12.12%)
Mutual labels:  threejs

three-render-objects

NPM package Build Size NPM Downloads

This module offers a convenient way to render ThreeJS objects onto a WebGL canvas, with built-in interaction capabilities:

  • hover/click events
  • tooltips
  • camera movement with animated transitions
  • trackball, orbit or fly controls

All the renderer/scene/camera scaffolding is already included and any instance of Object3D can be rendered with minimal setup.

Quick start

import ThreeRenderObjects from 'three-render-objects';

or

const ThreeRenderObjects = require('three-render-objects');

or even

<script src="//unpkg.com/three-render-objects"></script>

then

const myCanvas = ThreeRenderObjects();
myCanvas(<myDOMElement>)
  .objects(<myData>);

API reference

Initialisation

ThreeRenderObjects({ configOptions })(<domElement>)
Config options Description Default
controlType: str Which type of control to use to control the camera. Choice between trackball, orbit or fly. trackball
rendererConfig: object Configuration parameters to pass to the ThreeJS WebGLRenderer constructor. { antialias: true, alpha: true }
extraRenderers: array If you wish to include objects that require a dedicated renderer besides WebGL, such as CSS3DRenderer, include in this array those extra renderer instances. []
waitForLoadComplete: boolean Whether to wait until all the asynchronous loading operations are finished (such as the background image) before rendering the objects in the scene for the first time. true

Data input

Method Description Default
objects([array]) Getter/setter for the list of objects to render. Each object should be an instance of Object3D. []

Container layout

Method Description Default
width([px]) Getter/setter for the canvas width. <window width>
height([px]) Getter/setter for the canvas height. <window height>
skyRadius([number]) Radius of the sphere that bounds the scene, in GL units. 50000
backgroundColor([str]) Getter/setter for the canvas background color. #000011
backgroundImageUrl([url]) Getter/setter for the URL of the image to be used as scene background. If no image is provided, the background color is shown instead. null
onBackgroundImageLoaded([fn]) Callback function triggered when the background image has finished loading asynchronously and is rendered on the scene.
showNavInfo([boolean]) Getter/setter for whether to show the navigation controls footer info. true

Render control

Method Description Default
tick() Re-render all the objects on the canvas. Essentially this method should be called at every frame, and can be used to control the animation ticks.
cameraPosition([{x,y,z}], [lookAt], [ms]) Getter/setter for the camera position, in terms of x, y, z coordinates. Each of the coordinates is optional, allowing for motion in just some dimensions. The optional second argument can be used to define the direction that the camera should aim at, in terms of an {x,y,z} point in the 3D space at the distance of 1000 away from the camera. The 3rd optional argument defines the duration of the transition (in ms) to animate the camera motion. A value of 0 (default) moves the camera immediately to the final position. By default the camera will face the center of the graph at a z distance of 1000.
zoomToFit([ms], [px], [objFilterFn]) Automatically moves the camera so that all of the objects in the scene become visible within its field of view, while aiming at the scene center (0,0,0). If no objects are found no action is taken. It accepts three optional arguments: the first defines the duration of the transition (in ms) to animate the camera motion (default: 0ms). The second argument is the amount of padding (in px) between the edge of the canvas and the outermost object position (default: 10px). The third argument specifies a custom object filter: obj => <boolean>, which should return a truthy value if the object is to be included. This can be useful for focusing on a portion of the scene. (0, 10, obj => true)
fitToBbox(bbox, [ms], [px], [objFilterFn]) Automatically moves the camera to fit the specified bounding box within its field of view, while aiming at the scene center (0,0,0). The bounding box should follow the syntax { x: [<num>, <num>], y: [<num>, <num>], z: [<num>, <num>] }. If no bounding box is specified no action is taken. It accepts two optional arguments: the first defines the duration of the transition (in ms) to animate the camera motion (default: 0ms). The second argument is the amount of padding (in px) between the edge of the canvas and the outermost object position (default: 10px). (0, 10)
postProcessingComposer() Access the post-processing composer. Use this to add post-processing rendering effects to the scene. By default the composer has a single pass (RenderPass) that directly renders the scene without any effects.
renderer() Access the WebGL renderer object.
camera() Access the perspective camera object.
scene() Access the Scene object.
controls() Access the camera controls object.

Interaction

Method Description Default
onClick(fn) Callback function for object clicks with left mouse button. The object (or null if there's no object under the mouse line of sight), the event object and the coordinates of the intersecting point in the object's surface are included as arguments onClick(object, event, { x, y, z }). -
onRightClick(fn) Callback function for object right-clicks. The object (or null if there's no object under the mouse line of sight), the event object and the coordinates of the intersecting point in the object's surface are included as arguments onRightClick(object, event, { x, y, z }). -
onHover(fn) Callback function for object mouse over events. The object (or null if there's no object under the mouse line of sight) is included as the first argument, and the previous hovered object (or null) as second argument: onHover(obj, prevObj). -
hoverOrderComparator([fn]) Getter/setter for the comparator function to use when hovering over multiple objects under the same line of sight. This function can be used to prioritize hovering some objects over others. By default, hovering priority is based solely on camera proximity (closest object wins).
hoverFilter([fn]) Getter/setter for the filter function that defines whether an object is eligible for hovering and other interactions. This function receives an object as sole argument and should return a boolean value () => true
lineHoverPrecision([int]) Getter/setter for the precision to use when detecting hover events over Line objects. 1
tooltipContent([str or fn]) Object accessor function or attribute for label (shown in tooltip). Supports plain text or HTML content.
enablePointerInteraction([boolean]) Getter/setter for whether to enable the mouse tracking events. This activates an internal tracker of the canvas mouse position and enables the functionality of object hover/click and tooltip labels, at the cost of performance. If you're looking for maximum gain in your render performance it's recommended to switch off this property. true
hoverDuringDrag([boolean]) Getter/setter for whether to trigger hover events while using the controls via pointer dragging. false
clickAfterDrag([boolean]) Getter/setter for whether to trigger a click event after dragging using the controls. false
getPointerPos() Getter for the current position of the pointer relative to the viewport, in { x, y } px coordinates.

Utility

Method Description
getBbox([objFilterFn]) Returns the current bounding box of the objects in the scene, formatted as { x: [<num>, <num>], y: [<num>, <num>], z: [<num>, <num>] }. If no objects are found, returns null. Accepts an optional argument to define a custom object filter: object => <boolean>, which should return a truthy value if the object is to be included. This can be useful to calculate the bounding box of a portion of the scene.
getScreenCoords(x, y, z) Utility method to translate 3D coordinates to the viewport domain. Given a set of x,y,z coordinates, returns the current equivalent {x, y} in viewport coordinates.
getSceneCoords(x, y, distance) Utility method to translate viewport distance coordinates to the scene 3D domain. Given a set of x,y viewport coordinates and distance from the camera, returns the current equivalent {x, y, z} in 3D scene coordinates. If no distance is provided, defaults to 0.
intersectingObjects(x, y) Utility method to retrieve the list of objects under the line of sight of the given viewport coordinates. Returns an array of intersectObject, sorted by distance (from closest to farthest).
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].