x_ite-off-parser 1.0.3 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/x_ite-off-parser.js +51 -32
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,10 +13,10 @@ Include the script after X_ITE:
|
|
|
13
13
|
|
|
14
14
|
```html
|
|
15
15
|
<script defer src="https://cdn.jsdelivr.net/npm/x_ite@15.0.3/dist/x_ite.min.js"></script>
|
|
16
|
-
<script defer src="https://cdn.jsdelivr.net/npm/x_ite-off-parser@1.0.
|
|
16
|
+
<script defer src="https://cdn.jsdelivr.net/npm/x_ite-off-parser@1.0.5/dist/x_ite-off-parser.min.js"></script>
|
|
17
17
|
<!-- or as ES module -->
|
|
18
18
|
<script type="module" src="https://cdn.jsdelivr.net/npm/x_ite@15.0.3/dist/x_ite.min.mjs"></script>
|
|
19
|
-
<script type="module" src="https://cdn.jsdelivr.net/npm/x_ite-off-parser@1.0.
|
|
19
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/x_ite-off-parser@1.0.5/dist/x_ite-off-parser.min.js"></script>
|
|
20
20
|
```
|
|
21
21
|
|
|
22
22
|
Now you can load OFF files:
|
package/dist/x_ite-off-parser.js
CHANGED
|
@@ -9,6 +9,7 @@ const Grammar = X3D .Expressions ({
|
|
|
9
9
|
// General
|
|
10
10
|
whitespaces: /[\x20\n\t\r,]+/y,
|
|
11
11
|
whitespacesNoLineTerminator: /[\x20\t]+/y,
|
|
12
|
+
untilEndOfLine: /[^\r\n]+/y,
|
|
12
13
|
comment: /#[^\r\n]*(?=[\r\n]|$)/y,
|
|
13
14
|
header: /OFF/y,
|
|
14
15
|
|
|
@@ -27,6 +28,7 @@ class OffParser extends X3D .X3DParser
|
|
|
27
28
|
{
|
|
28
29
|
super (scene);
|
|
29
30
|
|
|
31
|
+
this .lineNumber = 1;
|
|
30
32
|
this .coordIndex = [ ];
|
|
31
33
|
this .colors = [ ];
|
|
32
34
|
this .points = [ ];
|
|
@@ -44,7 +46,7 @@ class OffParser extends X3D .X3DParser
|
|
|
44
46
|
|
|
45
47
|
isValid ()
|
|
46
48
|
{
|
|
47
|
-
return this .input .match (
|
|
49
|
+
return this .input .match (/^OFF/);
|
|
48
50
|
}
|
|
49
51
|
|
|
50
52
|
parseIntoScene (resolve, reject)
|
|
@@ -61,7 +63,7 @@ class OffParser extends X3D .X3DParser
|
|
|
61
63
|
scene = this .getScene ();
|
|
62
64
|
|
|
63
65
|
if (!this .statements ())
|
|
64
|
-
throw new Error (
|
|
66
|
+
throw new Error (`Couldn't parse OFF file: Invalid file structure at line ${this .lineNumber}.`);
|
|
65
67
|
|
|
66
68
|
scene .setEncoding ("OFF");
|
|
67
69
|
scene .setProfile (browser .getProfile ("Interchange"));
|
|
@@ -77,7 +79,7 @@ class OffParser extends X3D .X3DParser
|
|
|
77
79
|
geometry = scene .createNode ("IndexedFaceSet"),
|
|
78
80
|
coordinate = scene .createNode ("Coordinate");
|
|
79
81
|
|
|
80
|
-
if (this .colors .length)
|
|
82
|
+
if (this .colors .length / 3 === this .numFaces)
|
|
81
83
|
{
|
|
82
84
|
const color = scene .createNode ("Color");
|
|
83
85
|
|
|
@@ -116,32 +118,6 @@ class OffParser extends X3D .X3DParser
|
|
|
116
118
|
return false;
|
|
117
119
|
}
|
|
118
120
|
|
|
119
|
-
comments ()
|
|
120
|
-
{
|
|
121
|
-
while (this .comment ())
|
|
122
|
-
;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
comment ()
|
|
126
|
-
{
|
|
127
|
-
this .whitespaces ();
|
|
128
|
-
|
|
129
|
-
if (Grammar .comment .parse (this))
|
|
130
|
-
return true;
|
|
131
|
-
|
|
132
|
-
return false;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
whitespaces ()
|
|
136
|
-
{
|
|
137
|
-
Grammar .whitespaces .parse (this);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
whitespacesNoLineTerminator ()
|
|
141
|
-
{
|
|
142
|
-
Grammar .whitespacesNoLineTerminator .parse (this);
|
|
143
|
-
}
|
|
144
|
-
|
|
145
121
|
header ()
|
|
146
122
|
{
|
|
147
123
|
return Grammar .header .parse (this);
|
|
@@ -192,6 +168,8 @@ class OffParser extends X3D .X3DParser
|
|
|
192
168
|
if (this .double ())
|
|
193
169
|
{
|
|
194
170
|
points .push (this .value);
|
|
171
|
+
|
|
172
|
+
this .untilEndOfLine ();
|
|
195
173
|
continue;
|
|
196
174
|
}
|
|
197
175
|
}
|
|
@@ -233,17 +211,18 @@ class OffParser extends X3D .X3DParser
|
|
|
233
211
|
|
|
234
212
|
if (this .int32 ())
|
|
235
213
|
{
|
|
236
|
-
|
|
214
|
+
colors .push (this .value / 255);
|
|
237
215
|
|
|
238
216
|
if (this .int32 ())
|
|
239
217
|
{
|
|
240
|
-
|
|
218
|
+
colors .push (this .value / 255);
|
|
241
219
|
|
|
242
220
|
if (this .int32 ())
|
|
243
|
-
colors .push (
|
|
221
|
+
colors .push (this .value / 255);
|
|
244
222
|
}
|
|
245
223
|
}
|
|
246
224
|
|
|
225
|
+
this .untilEndOfLine ();
|
|
247
226
|
continue;
|
|
248
227
|
}
|
|
249
228
|
|
|
@@ -253,6 +232,46 @@ class OffParser extends X3D .X3DParser
|
|
|
253
232
|
return true;
|
|
254
233
|
}
|
|
255
234
|
|
|
235
|
+
comments ()
|
|
236
|
+
{
|
|
237
|
+
while (this .comment ())
|
|
238
|
+
;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
comment ()
|
|
242
|
+
{
|
|
243
|
+
this .whitespaces ();
|
|
244
|
+
|
|
245
|
+
if (Grammar .comment .parse (this))
|
|
246
|
+
return true;
|
|
247
|
+
|
|
248
|
+
return false;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
whitespaces ()
|
|
252
|
+
{
|
|
253
|
+
if (Grammar .whitespaces .parse (this))
|
|
254
|
+
this .lines (this .result [0]);
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
whitespacesNoLineTerminator ()
|
|
258
|
+
{
|
|
259
|
+
Grammar .whitespacesNoLineTerminator .parse (this);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
untilEndOfLine ()
|
|
263
|
+
{
|
|
264
|
+
Grammar .untilEndOfLine .parse (this);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
lines (string)
|
|
268
|
+
{
|
|
269
|
+
const match = string .match (Grammar .LineFeed);
|
|
270
|
+
|
|
271
|
+
if (match)
|
|
272
|
+
this .lineNumber += match .length;
|
|
273
|
+
}
|
|
274
|
+
|
|
256
275
|
int32 ()
|
|
257
276
|
{
|
|
258
277
|
this .whitespacesNoLineTerminator ();
|