Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
three-subdivide
Advanced tools
Smooth subdivision surface modifier for use with three.js BufferGeometry.
This modifier uses the Loop (Charles Loop, 1987) subdivision surface algorithm to smooth modern three.js BufferGeometry.
At one point, three.js included a subdivision surface modifier in the extended examples, it was removed in r125. This modifier was originally based on the Catmull-Clark algorithm, which works best for geometry with convex coplanar n-gon faces. In three.js r60 the modifier was changed to use the Loop algorithm, which was designed to work better with triangle based meshes.
The Loop algorithm, however, doesn't always provide uniform results as the vertices are skewed toward the most used vertex positions. A triangle box (like BoxGeometry
for example) will favor some corners more than others. To alleviate this issue, this implementation includes an initial pass to split coplanar faces at their shared edges. It starts by splitting along the longest shared edge first, and then from that midpoint it splits to any remaining coplanar shared edges. This can be disabled by passing 'split' as false.
Also by default, this implementation inserts new UV coordinates, but does not average them using the Loop algorithm. In some cases (often in flat geometries) this will produce undesired results, a noticeable tearing will occur. In such cases, try passing 'uvSmooth' as true to enable UV averaging.
LoopSubdivision.js
, import from file...import { LoopSubdivision } from 'LoopSubdivision.js';
npm install three-subdivide
import { LoopSubdivision } from 'three-subdivide';
import { LoopSubdivision } from 'https://unpkg.com/three-subdivide/build/index.module.js';
To create subdivided geometry, use the static function modify()
. The following code creates a cube with smoothed geometry and adds it to a three.js Scene
.
import * as THREE from 'three';
import { LoopSubdivision } from 'LoopSubdivision.js';
const iterations = 1;
const params = {
split: true, // optional, default: true
uvSmooth: false, // optional, default: false
preserveEdges: false, // optional, default: false
flatOnly: false, // optional, default: false
maxTriangles: Infinity, // optional, default: Infinity
};
const geometry = LoopSubdivision.modify(new THREE.BoxGeometry(), iterations, params);
const material = new THREE.MeshNormalMaterial();
const mesh = new THREE.Mesh(geometry, material);
const scene = new THREE.Scene();
scene.add(mesh);
LoopSubdivision.modify(bufferGeometry, iterations = 1, params = {}) {
Parameters Object ('params')
NOTE: This modifier converts geometry to non-indexed before the subdivision algorithm is applied. If desired, you can use BufferGeometryUtils.mergeVertices to re-index geometry.
FAQs
Smooth subdivision surface modifier for use with three.js BufferGeometry.
The npm package three-subdivide receives a total of 520 weekly downloads. As such, three-subdivide popularity was classified as not popular.
We found that three-subdivide demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.