Import color from ply file

ply file format is as follows
image

It is based on the webgl_loader_ply and I want to render the color information of the ply file.
The color is not applied and it comes out like the picture below.

	const loader = new PLYLoader();
				

				loader.load( './models/ply/test/basketball_player_vox11_00000001.ply', function ( geometry ) {

					geometry.computeVertexNormals();
					var material = new THREE.MeshPhongMaterial( { color: 0xffffff, specular: 0x111111, shininess: 200, vertexColors: THREE.VertexColors} );
					const mesh = new THREE.Mesh( geometry, material );

					mesh.position.x = - 0.2;
					mesh.position.y = - 0.52;
					mesh.position.z = - 0.0;
					mesh.scale.multiplyScalar( 0.0006 );

					mesh.castShadow = true;
					mesh.receiveShadow = true;

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

				} );

help me…

Do you mind sharing the PLY asset in this topic?

do you mean share the ply file?
The file is large and cannot be uploaded here.

uploaded here

The asset looks as expected in the three.js editor.

Since the PLY represents a point cloud, it’s important that you don’t create a mesh. Try it like so:

const material = new THREE.PointsMaterial( { size: 0.01, vertexColors: true } );
const object = new THREE.Points( geometry, material );

Besides, don’t call computeVertexNormals(). This is only relevant for meshes. You can also remove the lines mesh.castShadow = true; and mesh.receiveShadow = true; since point clouds do not cast or receive shadow.

2 Likes

Thank you very much. Very helpful.!!!

@Mugen87 i’ve been stuck for something similar for the past week.

It seems you are one of the few guys that can help me out.
If you want to do the same thing with ShaderMaterial instead of PointsMaterial. How would you go about it?

I am able to successfully pick up the position array and render a buffer geometry based on the positions… I thought I just have to pick up the attributes color array and enable vertex colors.

But using the same logic to map the positions to map the color array just isn’t working.