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

Overview

Three Subdivide

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

Live Demo

Screenshot

Loop Subdivision Demo

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 the corners. 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 (usually in round-ish geometries) this will produce undesired results, a noticeable tearing will occur. In such cases, try passing 'uvSmooth' as true to enable UV averaging.

Apply

LoopSubdivision.apply(bufferGeometry, iterations = 1, split = true, uvSmooth = false, flatOnly = false, maxTriangles = Infinity)

  • bufferGeometry : BufferGeometry - existing three.js BufferGeometry object.
  • iterations : Int (optional) - total passes of subdivision to apply, generally between 1 to 5.
  • split : Boolean (optional) - split coplanar faces at their shared edges before subdividing?
  • uvSmooth : Boolean (optional) - smooth UV coordinates 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.

Usage

To create subdivided geometry, use the static function apply(). 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 geometry = LoopSubdivision.apply(new THREE.BoxGeometry());

const material = new THREE.MeshNormalMaterial();
const mesh = new THREE.Mesh(geometry, material);

const scene = new THREE.Scene();
scene.add(mesh);

License

Subdivide is released under the terms of the MIT license, so it is free to use in your free or commercial projects.

Copyright (c) 2022 Stephens Nunnally <@stevinz>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You might also like...

Smooth mobile touch slider for Mobile WebApp, HTML5 App, Hybrid App

Smooth mobile touch slider for Mobile WebApp, HTML5 App, Hybrid App

iSlider iSlider is a lightweight, high-performant, no library dependencies cross-platform slide controller. It can help handling most sliding effects,

Nov 25, 2022

Smooth scroll animation - vanilla JavaScript

Smooth Scroll Animation Using Vanilla JavaScript Provides smooth scroll functionality on clicking buttons with different eeasing properties. The "smoo

Aug 14, 2022

A simple smooth scrolling using 100% vanilla JavaScript.

SmoothScroll.js A simple smooth scrolling using 100% vanilla JavaScript, and it's only 3kb! Demo Usage // index.html html head link rel="

Aug 24, 2022

A blazingly fast Bun.js filesystem router, with an unpleasantly smooth experience!

Oily A blazingly fast Bun.js filesystem router, with an unpleasantly smooth experience! Installation · Usage · Examples · Discord Installation Once yo

Dec 19, 2022

Smooth scrolling effect (while using mouse wheel). No jQuery or other unnecessary stuff needed.

scrooth Smooth scrolling effect (while using mouse wheel). No jQuery or other unnecessary stuff needed. Why? I needed that, and I was unable to find p

Aug 29, 2022

a Vanilla JS Smooth Scroll to ⚓ script

Smooth Scroll Library ScrollToSmooth Support for older versions: If you need documentation for versions prior 3.0.0 visit this page Lightweight Vanill

Aug 14, 2022

Generate smooth, consistent and always-sexy box-shadows, no matter the size, ideal for design token generation.

Generate smooth, consistent and always-sexy box-shadows, no matter the size, ideal for design token generation.

smooth-shadow Generate smooth, consistent and always-sexy box-shadows, no matter the size, ideal for design token generation. Demo As Tobias already p

Oct 15, 2022

Adding volumetric effects to a built-in Three.js shader.

Adding volumetric effects to a built-in Three.js shader.

Magical Marbles in Three.js Adding volumetric effects to a built-in Three.js shader. Article on Codrops Demo Installation Install dependencies: yarn

Dec 9, 2022

Interactive 3D plotting with a simple function call using Three.js

Interactive 3D plotting with a simple function call using Three.js

About Generate interactive 3d plots with a simple function call. Function returns a Three.js scene which can be customized as needed. Basic function c

Oct 20, 2022
Comments
  • About application to glTF animation

    About application to glTF animation

    Hello. I found it a great project. But would it be difficult to apply it to glTF animation?

    my code:

      // Morphing Animation at the top of the screen
      gltfMesh = gltf.scene.children[ 0 ];
      gltfMesh.scale.set( 1.5, 1.5, 1.5 );
      gltfMesh = gltf.scene;
      originalGeometry = gltfMesh.children[0].geometry;
      scene.add( gltfMesh );
      mixer = new THREE.AnimationMixer( gltfMesh );
      mixer.clipAction( gltf.animations[ 1 ] ).setDuration( 5 ).play();
      
      
      // Mesh with subdivisions applied at the bottom of the screen
      const geometry = LoopSubdivision.modify(originalGeometry);
      const material = new THREE.MeshNormalMaterial();
      const gltfMesh_sub = new THREE.Mesh(geometry, material);
      scene.add( gltfMesh_sub );					
      mixer_sub = new THREE.AnimationMixer( gltfMesh_sub );
      mixer_sub.clipAction( gltf.animations[ 1 ] ).setDuration( 5 ).play();
    

    https://user-images.githubusercontent.com/868060/185723390-98f9d10b-3e14-43cd-a74d-4f8658efa171.mp4 To me it looks like the keyframe animation is disappearing.

    What I am trying to do is https://threejs.org/examples/webgl_morphtargets_horse.html I am trying to apply a subdivision surface to an animation like this sample

    opened by niuin 7
Releases(v1.1.2)
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Combine type and value imports using Typescript 4.5 type modifier syntax

type-import-codemod Combines your type and value imports together into a single statement, using Typescript 4.5's type modifier syntax. Before: import

Ian VanSchooten 4 Sep 29, 2022
three.js examples. if you are first in learning three.js , this will give you much help.

three-projected-material Three.js Material which lets you do Texture Projection on a 3d Model. Installation After having installed three.js, install i

null 22 Nov 2, 2022
Text Engraving & Extrusion demo based on Three.js is implemented with Typescript and webpack5. Used THREE-CSGMesh as the core tech to achieve engraving and extrusion results

Text Engraving & Extrusion Text Engraving & Extrusion demo is implemented using Three.js, with Typescript and webpack5. Used THREE-CSGMesh as the core

Jiahong Li 3 Oct 12, 2022
A collection of preloaded and essential files that makes the website more attractive, smooth and user friendly

Web-Docs A collection of preloaded and essential files that makes the website more attractive, smooth and user friendly How to use: git clone https://

MAINAK CHAUDHURI 23 Dec 17, 2022
SafeCycle—a tool that keeps cyclists safe. Gone are days of weaving through busy city streets, SafeCycle finds all the bike routes for you to ensure a smooth ride wherever you want to go.

Inspiration Biking—an everyday form of travel for students and professionals across the globe. On-campus, back home, and with the people that we know

Ryan Hu 2 May 2, 2022
A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website.

Cuberto Mouse Follower A powerful javascript library to create amazing and smooth effects for the mouse cursor on your website. Dependencies GSAP v3 (

Cuberto 410 Dec 30, 2022
A-Frame components for smooth locomotion and snap turning

A-Frame locomotion A collection of A-Frame components, systems and primitives that enable all sorts of locomotion in VR. It't built to be modular, fle

Noeri Huisman 18 Sep 1, 2022