merge vertices
by felixmariotto
JavaScript
import * as THREE from "https://cdn.skypack.dev/three@0.129.0/build/three.module.js";
import { OrbitControls } from "https://cdn.skypack.dev/three@0.129.0/examples/jsm/controls/OrbitControls.js";
import { BufferGeometryUtils } from 'https://cdn.skypack.dev/three@0.129.0/examples/jsm/utils/BufferGeometryUtils.js';
const WIDTH = window.innerWidth;
const HEIGHT = window.innerHeight;
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, WIDTH / HEIGHT, 0.1, 1000 );
camera.position.set( 2, 5, 5 );
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize( WIDTH, HEIGHT );
document.body.appendChild( renderer.domElement );
const controls = new OrbitControls( camera, renderer.domElement );
//
let boxGeometry = new THREE.BoxGeometry();
boxGeometry.deleteAttribute( 'normal' );
boxGeometry.deleteAttribute( 'uv' );
boxGeometry = BufferGeometryUtils.mergeVertices( boxGeometry );
// normals where removed, so we recompute them.
boxGeometry.computeVertexNormals();
const mesh = new THREE.Mesh(
boxGeometry,
new THREE.MeshNormalMaterial()
);
scene.add( mesh );
//
function animate() {
requestAnimationFrame( animate );
renderer.render( scene, camera );
};
animate();