-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ad5728
commit 25d45d2
Showing
10 changed files
with
144 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,151 @@ | ||
import SurfaceParser from "./surface-parser"; | ||
import { BufferGeometry, Color } from "three"; | ||
/** | ||
* @file Ply Parser | ||
* @author Alexander Rose <[email protected]> | ||
* @private | ||
*/ | ||
import SurfaceParser from './surface-parser'; | ||
/** | ||
* PLYLoader | ||
* @class | ||
* @private | ||
* @author Wei Meng / http://about.me/menway | ||
* Port of PLYLoader from the MIT-licensed three.js project: | ||
* https://github.com/mrdoob/three.js/blob/97b5d428d598228cae9b206d9a321f18d53a3e86/examples/jsm/loaders/PLYLoader.js | ||
* | ||
* The original code has been modified to work with NGL and TypeScript. | ||
* Adaptation by @fredludlow | ||
* | ||
* @description | ||
* A THREE loader for PLY ASCII files (known as the Polygon File Format or the Stanford Triangle Format). | ||
* Description: A THREE loader for PLY ASCII files (known as the Polygon | ||
* File Format or the Stanford Triangle Format). | ||
* | ||
* Limitations: ASCII decoding assumes file is UTF-8. | ||
* | ||
* @example | ||
* var loader = new THREE.PLYLoader(); | ||
* loader.load('./models/ply/ascii/dolphins.ply', function (geometry) { | ||
* scene.add( new THREE.Mesh( geometry ) ); | ||
* } ); | ||
* Usage: | ||
* const loader = new PLYLoader(); | ||
* loader.load('./models/ply/ascii/dolphins.ply', function (geometry) { | ||
* | ||
* scene.add( new THREE.Mesh( geometry ) ); | ||
* | ||
* } ); | ||
* | ||
* // If the PLY file uses non standard property names, they can be mapped while | ||
* // loading. For example, the following maps the properties | ||
* // “diffuse_(red|green|blue)” in the file to standard color names. | ||
* If the PLY file uses non standard property names, they can be mapped while | ||
* loading. 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' | ||
* diffuse_red: 'red', | ||
* diffuse_green: 'green', | ||
* diffuse_blue: 'blue' | ||
* } ); | ||
* | ||
* Custom properties outside of the defaults for position, uv, normal | ||
* and color attributes can be added using the setCustomPropertyNameMapping 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. | ||
* Attribute item sizes are set from the number of element properties in the property array. | ||
* | ||
* loader.setCustomPropertyNameMapping( { | ||
* customAttribute: ['custom_property_a', 'custom_property_b'], | ||
* } ); | ||
* | ||
*/ | ||
export interface _PLYLoader { | ||
declare const dataTypes: readonly ["int8", "char", "uint8", "uchar", "int16", "short", "uint16", "ushort", "int32", "int", "uint32", "uint", "float32", "float", "float64", "double"]; | ||
declare type DataType = (typeof dataTypes)[number]; | ||
interface HeaderText { | ||
headerText: string; | ||
headerLength: number; | ||
} | ||
interface BasePLYProperty { | ||
type: DataType; | ||
name: string; | ||
valueReader?: BinaryReader; | ||
} | ||
interface SinglePLYProperty extends BasePLYProperty { | ||
isList: false; | ||
} | ||
interface BinarySinglePLYProperty extends SinglePLYProperty { | ||
valueReader: BinaryReader; | ||
} | ||
interface ListPLYProperty extends BasePLYProperty { | ||
isList: true; | ||
countType: DataType; | ||
countReader?: BinaryReader; | ||
} | ||
interface BinaryListPLYProperty extends ListPLYProperty { | ||
countReader: BinaryReader; | ||
valueReader: BinaryReader; | ||
} | ||
declare type PLYProperty = SinglePLYProperty | ListPLYProperty; | ||
declare type BinaryPLYProperty = BinarySinglePLYProperty | BinaryListPLYProperty; | ||
interface PLYElement { | ||
name: string; | ||
count: number; | ||
properties: PLYProperty[]; | ||
x: number; | ||
y: number; | ||
z: number; | ||
red: number; | ||
green: number; | ||
blue: number; | ||
[k: string]: any; | ||
} | ||
declare type PLYElementSpec = Pick<PLYElement, 'name' | 'count' | 'properties'>; | ||
interface PLYHeader { | ||
format: string; | ||
version: string; | ||
comments: string[]; | ||
elements: PLYElementSpec[]; | ||
headerLength: number; | ||
objInfo: string; | ||
} | ||
/** JS object that we generate the buffer from */ | ||
interface PLYBuffer { | ||
indices: number[]; | ||
vertices: number[]; | ||
normals: number[]; | ||
uvs: number[]; | ||
faceVertexUvs: number[]; | ||
colors: number[]; | ||
faceVertexColors: number[]; | ||
[k: string]: number[]; | ||
} | ||
declare type BinaryReader = { | ||
read: (at: number) => number; | ||
size: number; | ||
}; | ||
declare class PLYLoader { | ||
propertyNameMapping: { | ||
[k: string]: string; | ||
}; | ||
customPropertyMapping: { | ||
[k: string]: string; | ||
}; | ||
_color: Color; | ||
constructor(); | ||
setPropertyNameMapping(mapping: { | ||
[k: string]: string; | ||
}): void; | ||
createBuffer(): PLYBuffer; | ||
extractHeaderText(bytes: Uint8Array): HeaderText; | ||
handleElement(buffer: PLYBuffer, elementName: string, element: PLYElement, cacheEntry: MappedAttributes): void; | ||
parse(data: string | ArrayBuffer): BufferGeometry; | ||
parseHeader(data: string, headerLength?: number): PLYHeader; | ||
parseASCII(data: string, header: PLYHeader): BufferGeometry; | ||
parseBinary(data: Uint8Array, header: PLYHeader): BufferGeometry; | ||
postProcess(buffer: PLYBuffer): BufferGeometry; | ||
/** Augments properties with their appropriate valueReader attribute and | ||
* countReader if the property is a list type | ||
*/ | ||
makeBinaryProperties(properties: PLYProperty[], body: DataView, little_endian: boolean): BinaryPLYProperty[]; | ||
} | ||
declare function mapElementAttributes(properties: PLYProperty[]): { | ||
attrX: string; | ||
attrY: string; | ||
attrZ: string; | ||
attrNX: string | null; | ||
attrNY: string | null; | ||
attrNZ: string | null; | ||
attrS: string | null; | ||
attrT: string | null; | ||
attrR: string | null; | ||
attrG: string | null; | ||
attrB: string | null; | ||
}; | ||
declare type MappedAttributes = ReturnType<typeof mapElementAttributes>; | ||
declare class PlyParser extends SurfaceParser { | ||
get type(): string; | ||
getLoader(): _PLYLoader; | ||
getLoader(): PLYLoader; | ||
} | ||
export default PlyParser; |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters