您好,欢迎来到钮旅网。
搜索
您的当前位置:首页three.js 给PLY增加根据Z值设置颜色值

three.js 给PLY增加根据Z值设置颜色值

来源:钮旅网
		//    let          s = '../src/assets/ply/Result.ply'
		let s = plyUrl;  
		loader.load(s,
			function (geometry) {
				console.log('loader.load ');
				console.log(geometry);
				geometry.computeVertexNormals();

				const colorsArr = geometry.getAttribute('position').array.slice();
				//const colors = [];

				let colors = new Float32Array(colorsArr.length)
				console.log('colors', colorsArr)
				for (let i = 0; i < colorsArr.length; i++) {
					if ((i + 1) % 3 == 0)
					{
						colors[i-2] = Math.abs(colorsArr[i]) / 100;
						colors[i-1] = Math.abs(colorsArr[i]) / 400;
						colors[i-0] = Math.abs(colorsArr[i]) / 700;
						//colors.push(0.6, 0.5, Math.abs(colorsArr[i]) / colorsArr.length);
					}
						
				}

				console.log(colors)


				geometry.setAttribute('color', new THREE.BufferAttribute(colors, 3, false));


				const material2 = new THREE.PointsMaterial({ size: 0.001, vertexColors: true, color: '#ffff00', });//THREE.VertexColors color: '#ffff00',
				//material2.sizeAttenuation = false; 		



				let mesh2 = new THREE.Points(geometry, material2);
				mesh2.position.x = 1;//0;
				mesh2.position.y = 2;//-1;
				mesh2.position.z = 3;//0;
				mesh2.scale.multiplyScalar(0.4);
				mesh2.castShadow = true;
				mesh2.receiveShadow = true;
				scene.add(mesh2);


				scene.background = new THREE.Color(0x525b);
				console.log('loader.load OK');


				//}

				// 更新点云对象的顶点颜色属性
				// const attribute = new THREE.Uint8ClampedArray(colors).buffer;
				// geometry.setAttribute('color', new THREE.InterleavedBufferAttribute(attribute, 6, 39));


			},
			function (xhr) {
				//console.log((xhr.loaded / xhr.total) * 100 + "% loaded");
			},
			function (err) {
				console.error(err);
			}
		);

效果如下图 

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- niushuan.com 版权所有 赣ICP备2024042780号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务