simplifierModifier vertex colors

Hi.

When you use the Class SimplifyModifier with a BufferGeometry with vertex colors inside the result don’t preserve colors.

Mesh.geometry.attributes.color

Would it be possible to make a improved version of this class in order to take into account internal BufferAttributes?

Many thanks in advanced.

Here a basic example:

Just put the following code into a threejs.live.

You will se that the first geometry contains 2 attributes, color and pn_UUID, after the simplication the result only contains color but not with the proper values (in the not-simplified BufferGeometry are random colors and in the result after simplication colors are set to 1. The other attributes is not existing in the simplied result.

<!DOCTYPE html>
<html lang="en">
	<head><base href="./three.js/examples/" target="_blank">
		<title>three.js webgl - modifier - Subdivisions using Loop Subdivision Scheme</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
		<style>
			body {
				font-family: Monospace;
				background-color: #f0f0f0;
				margin: 0px;
				overflow: hidden;
			}
		</style>
	</head>
	<body>

		<script src="../build/three.js"></script>
		<script src="js/controls/OrbitControls.js"></script>
		<script src="js/modifiers/SimplifyModifier.js"></script>
		<script src="js/libs/stats.min.js"></script>

		<script>

			var container, stats;

			var camera, controls, scene, renderer;

			var cube, mesh, material;

			var boxGeometry = new THREE.TorusKnotBufferGeometry( 10, 3, 100, 16 );
          	var colorArray = new Float32Array(boxGeometry.attributes.position.count);
            for (var i=0; i<colorArray.length; i++){
            	colorArray[i] = Math.random();
           	}       
            boxGeometry.addAttribute('color', new THREE.BufferAttribute(colorArray), 3, true);
          	var pn_UUIDArray = new Uint32Array(boxGeometry.attributes.position.count);
          	for (var i=0; i<pn_UUIDArray.length; i++){
            	pn_UUIDArray[i] = i;
           	}  
          	boxGeometry.addAttribute('pn_UUID', new THREE.BufferAttribute(pn_UUIDArray), 3, true);
          	
            console.log(boxGeometry);
			var torusGeometry = new THREE.TorusBufferGeometry( 50, 25, 8, 8, Math.PI * 2 );
			var sphereGeometry = new THREE.SphereBufferGeometry( 50, 15, 15 );
			var planeGeometry = new THREE.PlaneBufferGeometry( 100, 100, 6, 6 );
			var textGeometry;

			var loader = new THREE.FontLoader();
			loader.load( 'fonts/helvetiker_regular.typeface.json', function ( font ) {

					textGeometry = new THREE.TextGeometry( '&', {
					size: 200,
					height: 50,
					curveSegments: 1,
					font: font
				} );

			} );

			var modifer = new THREE.SimplifyModifier();
			var meshes = [];
			var count = 0;


			init();
			animate();


			function addStuff( geometry ) {
				count ++;

				var simplified = new THREE.BufferGeometry().fromGeometry( modifer.modify( geometry, geometry.attributes.position.count * 0.1 | 0 ) );
				console.log(simplified);
				var wireframe = new THREE.MeshBasicMaterial({
					color: Math.random() * 0xffffff,
					wireframe: true
				});

				var materialNormal = new THREE.MeshNormalMaterial({
					transparent: true,
					opacity: 0.7

				});

				mesh = THREE.SceneUtils.createMultiMaterialObject( simplified, [
					material,
					wireframe,
					// materialNormal
				]);

				mesh.position.x = -200;
				mesh.position.y = count * 150 - 300;

				scene.add( mesh );
				meshes.push( mesh );


				mesh = THREE.SceneUtils.createMultiMaterialObject( geometry, [
					material,
					wireframe,
					// materialNormal
				]);

				mesh.position.x = 200;
				mesh.position.y = count * 150 - 300;
				scene.add( mesh );
				meshes.push ( mesh );

			}

			function init() {

				container = document.createElement( 'div' );
				document.body.appendChild( container );

				info = document.createElement( 'div' );
				info.style.position = 'absolute';
				info.style.top = '10px';
				info.style.width = '100%';
				info.style.textAlign = 'center';
				info.innerHTML = '50% Vertex Reduction using SimplifyModifier';
				container.appendChild( info );

				camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 1000 );
				camera.position.z = 500;

				scene = new THREE.Scene();

				var light = new THREE.PointLight( 0xffffff, 1.5 );
				light.position.set( 1000, 1000, 2000 );
				scene.add( light );

				addStuff( planeGeometry );
				addStuff( boxGeometry );
				addStuff( sphereGeometry );
				addStuff( torusGeometry );





				renderer = new THREE.WebGLRenderer( { antialias: true } );
				renderer.setClearColor( 0xf0f0f0 );
				renderer.setPixelRatio( window.devicePixelRatio );
				renderer.setSize( window.innerWidth, window.innerHeight );
				container.appendChild( renderer.domElement );

				stats = new Stats();
				container.appendChild( stats.dom );

				//

				controls = new THREE.OrbitControls( camera, renderer.domElement );

				window.addEventListener( 'resize', onWindowResize, false );

			}

			function onWindowResize() {

				camera.aspect = window.innerWidth / window.innerHeight;
				camera.updateProjectionMatrix();

				renderer.setSize( window.innerWidth, window.innerHeight );

			}

			//

			function animate() {

				meshes.forEach( m => {
					m.rotation.x += 0.01;
					m.rotation.y += 0.01;
					m.rotation.z += 0.01;
				})

				requestAnimationFrame( animate );

				controls.update();

				stats.begin();
				render();
				stats.end();

			}

			function render() {

				renderer.render( scene, camera );

			}

		</script>

	</body>
</html>