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-subdivide

v1.1.5

Published

Smooth subdivision surface modifier for use with three.js BufferGeometry.

Downloads

8,146

Readme

Three Subdivide

This modifier uses the Loop (Charles Loop, 1987) subdivision surface algorithm to smooth modern three.js BufferGeometry.

Examples

  • Three.js Built-In Geometries

  • Morph Target Animation

Screenshot

Background

       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.

Install

  • Option 1: Copy file LoopSubdivision.js, import from file...
import { LoopSubdivision } from 'LoopSubdivision.js';
  • Option 2: Install from npm, import from 'three-subdivide'...
npm install three-subdivide
import { LoopSubdivision } from 'three-subdivide';
  • Option 3: Import directly from CDN...
import { LoopSubdivision } from 'https://unpkg.com/three-subdivide/build/index.module.js';

Usage

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);

Modify

LoopSubdivision.modify(bufferGeometry, iterations = 1, params = {}) {

  • bufferGeometry : BufferGeometry - existing three.js BufferGeometry object to be subdivided
  • iterations : Int (optional) - total passes of subdivision to apply, generally between 1 to 5
  • params : Object (optional) - optional parameters object, see below

Parameters Object ('params')

  • split : Boolean (optional) - split coplanar faces at their shared edges before subdividing?
  • uvSmooth : Boolean (optional) - smooth UV coordinates during subdivision?
  • preserveEdges Boolean (optional) - should edges / breaks in geometry be ignored during subdivision?
  • flatOnly : Boolean (optioanl) - subdivide triangles but do not apply smoothing?
  • maxTriangles : Number (optional) - limits subdivision to meshes with less than this number of triangles

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.