Lital
April 30, 2020, 12:07pm
1
I have a PLY file with a custom attribute of values, which I would like to load and use. Is there a way to do that?
In the PLYReader I saw there’s an option to map custom attributes to default attributes, is there a similar option for dracoLoader as well?
Here’s an example of a header:
ply
format binary_little_endian 1.0
element vertex 27549
property float x
property float y
property float z
property float Depth
property float Points
property float Direction
element face 54252
property list uchar uint vertex_indices
end_header
I would like to read the Depth attribute.
Can you please share the code that performs this mapping? AFAIK, PLYLoader
just supports the mapping of custom property names to default names.
Lital
April 30, 2020, 12:26pm
3
I was trying to use this code, but the mapping actually didn’t work for me, not sure why.
import { PLYLoader } from 'three/examples/jsm/loaders/PLYLoader';
.
this.plyLoader = new PLYLoader();
this.plyLoader.load(visualModel, (geometry) => {
geometry.computeVertexNormals();
this.plyLoader.setPropertyNameMapping({
Depth: 'position'
});
mesh = new THREE.Mesh( geometry, material );
mesh.scale.set(2, 2, 2);
this.scene.add(mesh);
this.loading = false;
},
( xhr ) => {
console.log( ( xhr.loaded / xhr.total * 100 ) + '% loaded' );
});
PLYLoader.setPropertyNameMapping()
does not work like that. Consider vertex colors. You normally define them like so:
property uchar red
property uchar green
property uchar blue
However, you could have a PLY
asset where the definition is:
property uchar diffuse_red
property uchar diffuse_green
property uchar diffuse_blue
You now have to define a property mapping otherwise PLYLoader
is unable to load the asset:
loader.setPropertyNameMapping( {
diffuse_red: 'red',
diffuse_green: 'green',
diffuse_blue: 'blue'
} );
That is required since PLYLoader
looks for a fixed set of data/properties. If you have additional values in your asset (like Depth
), it’s not possible to parse them without modifying the loader.
Lital
April 30, 2020, 12:58pm
5
Oh, ok. Thanks for the clarification.
Is there a different loader that does support this functionality? Perhaps GltfLoader?
Not that I am aware of, sorry.
Lital
April 30, 2020, 1:03pm
7
Ok. Do you know where I can find a list of the fixed set of properties the plyLoader (or better yet the dracoLoader) support?
I suggest you just look into the source code^^.
Mugen87
November 24, 2022, 9:00am
9
Thanks to @alankalb at GitHub, it will be possible with r147
to load custom attributes in PLY files with PLYLoader
, see:
mrdoob:dev
← alankalb:plyloader_custom_attributes
opened 11:37PM - 21 Nov 22 UTC
Related discussion: https://discourse.threejs.org/t/dracoloader-how-to-read-cust… om-attributes/14785
**Description**
When creating a .ply file, it is possible to add custom element properties that do not map to the default buffer attributes for position, normal, uv and color that are included in the PLYLoader. This adds the ability to map custom element properties to a new buffer attribute.
A new property, `customPropertyMapping` was added to PLYLoader and can be set via the method `setCustomPropertyNameMapping`. The name of the new buffer attribute is added as the object key and the element properties are added as the object value as a list. For example, the following will map the element properties `custom_property_a` and `custom_property_b` to the attribute `customAttribute`:
```js
loader.setCustomPropertyMapping( {
customAttribute: ['custom_property_a', 'custom_property_b'],
} );
```
The function `handleElement` within the `parse` method will find the value for each custom property in an element and push it to its corresponding customAttribute within the temporary `buffer` created in the `parseASCII` or `parseBinary` functions. `postProcess` will then set a new Float32BufferAttribute attribute on the geometry. The number of element properties in the properties list is used to set the item size of the attribute. From the example above the resulting geometry will have a `customAttribute` buffer attribute with an item size of 2.
This was tested with a .ply file with the following element properties:
```js
0: {type: 'double', name: 'x'}
1: {type: 'double', name: 'y'}
2: {type: 'double', name: 'z'}
3: {type: 'double', name: 'signed_distance'}
```
The `signed_distance` property was mapped to the attribute `signedDistance` using:
```js
loader.setCustomPropertyMapping( {
signedDistance: ['signed_distance'],
} );
```
Parsing the file resulted in a geometry with the following attributes:
```js
{
position: {
array: [...],
itemSize: 3,
...
},
signedDistance: {
array: [...],
itemSize: 1,
...
}
}
```