A loader for the PLY (Polygon File Format) file format, also known as the Stanford Triangle Format. [name] supports both ASCII and binary files as well as the following PLY properties:
[name] is an add-on, and must be imported explicitly. See [link:#manual/introduction/Installation Installation / Addons].
import { PLYLoader } from 'three/addons/loaders/PLYLoader.js';
// instantiate a loader
const loader = new PLYLoader();
// load a resource
loader.load(
// resource URL
'models/ply/ascii/dolphins.ply',
// called when the resource is loaded
function ( geometry ) {
// compute vertex normals if not present in the file
geometry.computeVertexNormals();
const material = new THREE.MeshStandardMaterial( { color: 0x0055ff } );
const mesh = new THREE.Mesh( geometry, material );
scene.add( mesh );
},
// called when loading is in progress
function ( xhr ) {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
},
// called when loading has errors
function ( error ) {
console.log( 'An error happened' );
}
);
[example:webgl_loader_ply]
[page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
Creates a new [name].
See the base [page:Loader] class for common properties.
An object that maps default property names to custom ones. Used for handling non-standard PLY property names.
An object that defines custom property mappings for attributes not covered by the standard position, normal, uv, and color properties.
See the base [page:Loader] class for common methods.
[page:String url] — A string containing the path/URL of the `.ply` file.
[page:Function onLoad] — (optional) A function to be called after loading is successfully completed. The function receives the loaded [page:BufferGeometry] as an argument.
[page:Function onProgress] — (optional) A function to be called while the loading is in progress. The argument will be the XMLHttpRequest instance, which contains [page:Integer total] and [page:Integer loaded] bytes. If the server does not set the Content-Length header; .[page:Integer total] will be 0.
[page:Function onError] — (optional) A function to be called if an error occurs during loading. The function receives the error as an argument.
Begin loading from url and call onLoad with the parsed response content.
[page:ArrayBuffer data] — The binary or text structure to parse.
Parse a PLY binary or ASCII structure and return a [page:BufferGeometry].
The geometry contains vertex positions and may include vertex normals, texture coordinates, vertex colors, and face indices depending on the PLY file content.
[page:Object mapping] — An object that maps default property names to custom ones.
Sets a property name mapping that maps default property names to custom ones. For example, the following maps the properties "diffuse_(red|green|blue)" in the file to standard color names:
loader.setPropertyNameMapping( {
diffuse_red: 'red',
diffuse_green: 'green',
diffuse_blue: 'blue'
} );
[page:Object mapping] — An object that defines custom property mappings.
Custom properties outside of the defaults for position, uv, normal and color attributes can be added using this method. For example, the following maps the element properties "custom_property_a" and "custom_property_b" to an attribute "customAttribute" with an item size of 2:
loader.setCustomPropertyNameMapping( {
customAttribute: ['custom_property_a', 'custom_property_b']
} );
[link:https://github.com/mrdoob/three.js/blob/master/examples/jsm/loaders/PLYLoader.js examples/jsm/loaders/PLYLoader.js]