three-stdlib 2.8.0 → 2.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. package/cameras/CinematicCamera.cjs.js +1 -1
  2. package/cameras/CinematicCamera.js +3 -8
  3. package/exporters/GLTFExporter.cjs.js +1 -1
  4. package/exporters/GLTFExporter.js +9 -18
  5. package/index.cjs.js +1 -1
  6. package/loaders/EXRLoader.cjs.js +1 -1
  7. package/loaders/EXRLoader.js +21 -10
  8. package/loaders/GLTFLoader.cjs.js +1 -1
  9. package/loaders/GLTFLoader.js +4 -3
  10. package/loaders/HDRCubeTextureLoader.cjs.js +1 -1
  11. package/loaders/HDRCubeTextureLoader.js +1 -3
  12. package/loaders/LDrawLoader.cjs.js +1 -1
  13. package/loaders/LDrawLoader.js +1450 -1105
  14. package/loaders/LUT3dlLoader.cjs.js +1 -1
  15. package/loaders/LUT3dlLoader.js +18 -11
  16. package/loaders/LUTCubeLoader.cjs.js +1 -1
  17. package/loaders/LUTCubeLoader.js +4 -5
  18. package/loaders/PCDLoader.cjs.js +1 -1
  19. package/loaders/PCDLoader.js +2 -2
  20. package/loaders/RGBELoader.cjs.js +1 -1
  21. package/loaders/RGBELoader.js +6 -6
  22. package/loaders/VRMLLoader.cjs.js +1 -1
  23. package/loaders/VRMLLoader.js +10 -18
  24. package/modifiers/CurveModifier.cjs.js +1 -1
  25. package/modifiers/CurveModifier.js +9 -8
  26. package/objects/Lensflare.cjs.js +1 -1
  27. package/objects/Lensflare.js +3 -11
  28. package/objects/Reflector.cjs.js +1 -1
  29. package/objects/Reflector.js +16 -12
  30. package/objects/ReflectorForSSRPass.cjs.js +1 -1
  31. package/objects/ReflectorForSSRPass.js +1 -9
  32. package/objects/Refractor.cjs.js +1 -1
  33. package/objects/Refractor.js +7 -12
  34. package/objects/Water.cjs.js +1 -1
  35. package/objects/Water.js +5 -16
  36. package/package.json +1 -1
  37. package/postprocessing/GlitchPass.cjs.js +1 -1
  38. package/postprocessing/GlitchPass.js +36 -33
  39. package/postprocessing/SMAAPass.cjs.js +1 -1
  40. package/postprocessing/SMAAPass.js +93 -96
  41. package/postprocessing/SSAOPass.cjs.js +1 -1
  42. package/postprocessing/SSAOPass.js +151 -152
  43. package/postprocessing/SavePass.cjs.js +1 -1
  44. package/postprocessing/SavePass.js +27 -28
  45. package/renderers/webgpu/WebGPUTextures.cjs.js +1 -1
  46. package/renderers/webgpu/WebGPUTextures.js +1 -2
  47. package/utils/LDrawUtils.cjs.js +1 -0
  48. package/utils/LDrawUtils.js +144 -0
@@ -0,0 +1,144 @@
1
+ import { Matrix3, Group, Mesh, LineSegments, BufferGeometry, BufferAttribute } from 'three';
2
+ import { m as mergeBufferGeometries } from '../BufferGeometryUtils-582025b8.js';
3
+ import '../types/helpers.js';
4
+
5
+ class LDrawUtils {
6
+ static mergeObject(object) {
7
+ // Merges geometries in object by materials and returns new object. Use on not indexed geometries.
8
+ // The object buffers reference the old object ones.
9
+ // Special treatment is done to the conditional lines generated by LDrawLoader.
10
+ function extractGroup(geometry, group, elementSize, isConditionalLine) {
11
+ // Extracts a group from a geometry as a new geometry (with attribute buffers referencing original buffers)
12
+ const newGeometry = new BufferGeometry();
13
+ const originalPositions = geometry.getAttribute('position').array;
14
+ const originalNormals = elementSize === 3 ? geometry.getAttribute('normal').array : null;
15
+ const numVertsGroup = Math.min(group.count, Math.floor(originalPositions.length / 3) - group.start);
16
+ const vertStart = group.start * 3;
17
+ const vertEnd = (group.start + numVertsGroup) * 3;
18
+ const positions = originalPositions.subarray(vertStart, vertEnd);
19
+ const normals = originalNormals !== null ? originalNormals.subarray(vertStart, vertEnd) : null;
20
+ newGeometry.setAttribute('position', new BufferAttribute(positions, 3));
21
+ if (normals !== null) newGeometry.setAttribute('normal', new BufferAttribute(normals, 3));
22
+
23
+ if (isConditionalLine) {
24
+ const controlArray0 = geometry.getAttribute('control0').array.subarray(vertStart, vertEnd);
25
+ const controlArray1 = geometry.getAttribute('control1').array.subarray(vertStart, vertEnd);
26
+ const directionArray = geometry.getAttribute('direction').array.subarray(vertStart, vertEnd);
27
+ newGeometry.setAttribute('control0', new BufferAttribute(controlArray0, 3, false));
28
+ newGeometry.setAttribute('control1', new BufferAttribute(controlArray1, 3, false));
29
+ newGeometry.setAttribute('direction', new BufferAttribute(directionArray, 3, false));
30
+ }
31
+
32
+ return newGeometry;
33
+ }
34
+
35
+ function addGeometry(mat, geometry, geometries) {
36
+ const geoms = geometries[mat.uuid];
37
+
38
+ if (!geoms) {
39
+ geometries[mat.uuid] = {
40
+ mat: mat,
41
+ arr: [geometry]
42
+ };
43
+ } else {
44
+ geoms.arr.push(geometry);
45
+ }
46
+ }
47
+
48
+ function permuteAttribute(attribute, elemSize) {
49
+ // Permutes first two vertices of each attribute element
50
+ if (!attribute) return;
51
+ const verts = attribute.array;
52
+ const numVerts = Math.floor(verts.length / 3);
53
+ let offset = 0;
54
+
55
+ for (let i = 0; i < numVerts; i++) {
56
+ const x = verts[offset];
57
+ const y = verts[offset + 1];
58
+ const z = verts[offset + 2];
59
+ verts[offset] = verts[offset + 3];
60
+ verts[offset + 1] = verts[offset + 4];
61
+ verts[offset + 2] = verts[offset + 5];
62
+ verts[offset + 3] = x;
63
+ verts[offset + 4] = y;
64
+ verts[offset + 5] = z;
65
+ offset += elemSize * 3;
66
+ }
67
+ } // Traverse the object hierarchy collecting geometries and transforming them to world space
68
+
69
+
70
+ const meshGeometries = {};
71
+ const linesGeometries = {};
72
+ const condLinesGeometries = {};
73
+ object.updateMatrixWorld(true);
74
+ const normalMatrix = new Matrix3();
75
+ object.traverse(c => {
76
+ if (c.isMesh | c.isLineSegments) {
77
+ const elemSize = c.isMesh ? 3 : 2;
78
+ const geometry = c.geometry.clone();
79
+ const matrixIsInverted = c.matrixWorld.determinant() < 0;
80
+
81
+ if (matrixIsInverted) {
82
+ permuteAttribute(geometry.attributes.position, elemSize);
83
+ permuteAttribute(geometry.attributes.normal, elemSize);
84
+ }
85
+
86
+ geometry.applyMatrix4(c.matrixWorld);
87
+
88
+ if (c.isConditionalLine) {
89
+ geometry.attributes.control0.applyMatrix4(c.matrixWorld);
90
+ geometry.attributes.control1.applyMatrix4(c.matrixWorld);
91
+ normalMatrix.getNormalMatrix(c.matrixWorld);
92
+ geometry.attributes.direction.applyNormalMatrix(normalMatrix);
93
+ }
94
+
95
+ const geometries = c.isMesh ? meshGeometries : c.isConditionalLine ? condLinesGeometries : linesGeometries;
96
+
97
+ if (Array.isArray(c.material)) {
98
+ for (const groupIndex in geometry.groups) {
99
+ const group = geometry.groups[groupIndex];
100
+ const mat = c.material[group.materialIndex];
101
+ const newGeometry = extractGroup(geometry, group, elemSize, c.isConditionalLine);
102
+ addGeometry(mat, newGeometry, geometries);
103
+ }
104
+ } else {
105
+ addGeometry(c.material, geometry, geometries);
106
+ }
107
+ }
108
+ }); // Create object with merged geometries
109
+
110
+ const mergedObject = new Group();
111
+ const meshMaterialsIds = Object.keys(meshGeometries);
112
+
113
+ for (const i in meshMaterialsIds) {
114
+ const meshGeometry = meshGeometries[meshMaterialsIds[i]];
115
+ const mergedGeometry = mergeBufferGeometries(meshGeometry.arr);
116
+ mergedObject.add(new Mesh(mergedGeometry, meshGeometry.mat));
117
+ }
118
+
119
+ const linesMaterialsIds = Object.keys(linesGeometries);
120
+
121
+ for (const i in linesMaterialsIds) {
122
+ const lineGeometry = linesGeometries[linesMaterialsIds[i]];
123
+ const mergedGeometry = mergeBufferGeometries(lineGeometry.arr);
124
+ mergedObject.add(new LineSegments(mergedGeometry, lineGeometry.mat));
125
+ }
126
+
127
+ const condLinesMaterialsIds = Object.keys(condLinesGeometries);
128
+
129
+ for (const i in condLinesMaterialsIds) {
130
+ const condLineGeometry = condLinesGeometries[condLinesMaterialsIds[i]];
131
+ const mergedGeometry = mergeBufferGeometries(condLineGeometry.arr);
132
+ const condLines = new LineSegments(mergedGeometry, condLineGeometry.mat);
133
+ condLines.isConditionalLine = true;
134
+ mergedObject.add(condLines);
135
+ }
136
+
137
+ mergedObject.userData.constructionStep = 0;
138
+ mergedObject.userData.numConstructionSteps = 1;
139
+ return mergedObject;
140
+ }
141
+
142
+ }
143
+
144
+ export { LDrawUtils };