MCPcopy Create free account
hub / github.com/pmndrs/postprocessing / parse

Method parse

src/loaders/LUTCubeLoader.js:91–164  ·  view source on GitHub ↗

* Parses the given data. * * @param {String} input - The LUT data. * @return {LookupTexture} The lookup texture. * @throws {Error} Fails if the data is invalid.

(input)

Source from the content-addressed store, hash-verified

89 */
90
91 parse(input) {
92
93 const regExpTitle = /TITLE +"([^"]*)"/;
94 const regExpSize = /LUT_3D_SIZE +(\d+)/;
95 const regExpDomainMin = /DOMAIN_MIN +([\d.]+) +([\d.]+) +([\d.]+)/;
96 const regExpDomainMax = /DOMAIN_MAX +([\d.]+) +([\d.]+) +([\d.]+)/;
97 const regExpDataPoints = /^([\d.e+-]+) +([\d.e+-]+) +([\d.e+-]+) *$/gm;
98
99 let result = regExpTitle.exec(input);
100 const title = (result !== null) ? result[1] : null;
101
102 result = regExpSize.exec(input);
103
104 if(result === null) {
105
106 throw new Error("Missing LUT_3D_SIZE information");
107
108 }
109
110 const size = Number(result[1]);
111 const data = new Float32Array(size ** 3 * 4);
112
113 const domainMin = new Vector3(0.0, 0.0, 0.0);
114 const domainMax = new Vector3(1.0, 1.0, 1.0);
115
116 result = regExpDomainMin.exec(input);
117
118 if(result !== null) {
119
120 domainMin.set(Number(result[1]), Number(result[2]), Number(result[3]));
121
122 }
123
124 result = regExpDomainMax.exec(input);
125
126 if(result !== null) {
127
128 domainMax.set(Number(result[1]), Number(result[2]), Number(result[3]));
129
130 }
131
132 if(domainMin.x > domainMax.x || domainMin.y > domainMax.y || domainMin.z > domainMax.z) {
133
134 domainMin.set(0.0, 0.0, 0.0);
135 domainMax.set(1.0, 1.0, 1.0);
136
137 throw new Error("Invalid input domain");
138
139 }
140
141 let i = 0;
142
143 while((result = regExpDataPoints.exec(input)) !== null) {
144
145 data[i++] = Number(result[1]);
146 data[i++] = Number(result[2]);
147 data[i++] = Number(result[3]);
148 data[i++] = 1.0;

Callers 1

loadMethod · 0.95

Calls 2

setMethod · 0.80
copyMethod · 0.80

Tested by

no test coverage detected