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

troika-three-utils

Package Overview
Dependencies
Maintainers
1
Versions
46
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

troika-three-utils

Various utilities related to Three.js

  • 0.41.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
229K
decreased by-15.56%
Maintainers
1
Weekly downloads
 
Created

What is troika-three-utils?

The troika-three-utils package provides a collection of utility functions and classes to simplify common tasks when working with Three.js, a popular 3D library for JavaScript. These utilities help with tasks such as geometry manipulation, shader management, and scene graph operations.

What are troika-three-utils's main functionalities?

Geometry Utilities

This feature allows you to merge multiple geometries into a single geometry. This can be useful for optimizing performance by reducing the number of draw calls.

const { mergeBufferGeometries } = require('troika-three-utils');
const geometry1 = new THREE.BoxGeometry(1, 1, 1);
const geometry2 = new THREE.SphereGeometry(0.5, 32, 32);
const mergedGeometry = mergeBufferGeometries([geometry1, geometry2]);

Shader Utilities

This feature allows you to create a derived material from an existing material, adding custom shaders and uniforms. This is useful for creating complex visual effects without having to write a new material from scratch.

const { createDerivedMaterial } = require('troika-three-utils');
const baseMaterial = new THREE.MeshStandardMaterial({ color: 0x00ff00 });
const derivedMaterial = createDerivedMaterial(baseMaterial, {
  uniforms: {
    time: { value: 0 }
  },
  vertexShader: 'varying float vTime; void main() { vTime = time; gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0); }',
  fragmentShader: 'varying float vTime; void main() { gl_FragColor = vec4(vTime, 0.0, 0.0, 1.0); }'
});

Scene Graph Utilities

This feature provides a utility to traverse the scene graph, applying a callback function to each object. This can be useful for operations like searching for specific objects or applying transformations.

const { traverseScene } = require('troika-three-utils');
const scene = new THREE.Scene();
const mesh = new THREE.Mesh(new THREE.BoxGeometry(), new THREE.MeshBasicMaterial());
scene.add(mesh);
traverseScene(scene, (object) => {
  console.log(object);
});
0

FAQs

Package last updated on 22 Apr 2021

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