PLYLoader: Allow custom attributes. #25001
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Related discussion: https://discourse.threejs.org/t/dracoloader-how-to-read-custom-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 methodsetCustomPropertyNameMapping
. 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 propertiescustom_property_a
andcustom_property_b
to the attributecustomAttribute
:The function
handleElement
within theparse
method will find the value for each custom property in an element and push it to its corresponding customAttribute within the temporarybuffer
created in theparseASCII
orparseBinary
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 acustomAttribute
buffer attribute with an item size of 2.This was tested with a .ply file with the following element properties:
The
signed_distance
property was mapped to the attributesignedDistance
using:Parsing the file resulted in a geometry with the following attributes: