Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

three-render-objects

Package Overview
Dependencies
Maintainers
1
Versions
116
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

three-render-objects

Easy way to render ThreeJS objects with built-in interaction defaults

  • 1.14.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
30K
decreased by-2.01%
Maintainers
1
Weekly downloads
 
Created
Source

three-render-objects

NPM package Build Size Dependencies

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

var 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 optionsDescriptionDefault
controlType: strWhich type of control to use to control the camera. Choice between trackball, orbit or fly.trackball
rendererConfig: objectConfiguration parameters to pass to the ThreeJS WebGLRenderer constructor.{ antialias: true, alpha: true }
waitForLoadComplete: booleanWhether 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

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

Container layout

MethodDescriptionDefault
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

MethodDescriptionDefault
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.
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

MethodDescriptionDefault
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) and the event object are included as arguments onClick(object, event).-
onRightClick(fn)Callback function for object right-clicks. The object (or null if there's no object under the mouse line of sight) and the event object are included as arguments onRightClick(object, event).-
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 (closes object wins).
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

Keywords

FAQs

Package last updated on 10 May 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc