ohzi-core 6.15.7 → 6.16.0
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/package.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { Vector3 } from 'three';
|
|
2
|
+
import { Vector2 } from 'three';
|
|
2
3
|
class MeshSampler
|
|
3
4
|
{
|
|
4
5
|
constructor()
|
|
@@ -14,6 +15,8 @@ class MeshSampler
|
|
|
14
15
|
|
|
15
16
|
const vertices = buffer_geometry.getAttribute('position');
|
|
16
17
|
const normals = buffer_geometry.getAttribute('normal');
|
|
18
|
+
const tangents = buffer_geometry.getAttribute('tangent');
|
|
19
|
+
const uvs = buffer_geometry.getAttribute('uv');
|
|
17
20
|
const indices = buffer_geometry.index;
|
|
18
21
|
|
|
19
22
|
const faces = [];
|
|
@@ -66,6 +69,45 @@ class MeshSampler
|
|
|
66
69
|
face.normal = normal;
|
|
67
70
|
}
|
|
68
71
|
|
|
72
|
+
if (tangents)
|
|
73
|
+
{
|
|
74
|
+
const n1 = new Vector3();
|
|
75
|
+
n1.x = tangents.getX(index_0);
|
|
76
|
+
n1.y = tangents.getY(index_0);
|
|
77
|
+
n1.z = tangents.getZ(index_0);
|
|
78
|
+
|
|
79
|
+
const n2 = new Vector3();
|
|
80
|
+
n2.x = tangents.getX(index_1);
|
|
81
|
+
n2.y = tangents.getY(index_1);
|
|
82
|
+
n2.z = tangents.getZ(index_1);
|
|
83
|
+
|
|
84
|
+
const n3 = new Vector3();
|
|
85
|
+
n3.x = tangents.getX(index_2);
|
|
86
|
+
n3.y = tangents.getY(index_2);
|
|
87
|
+
n3.z = tangents.getZ(index_2);
|
|
88
|
+
|
|
89
|
+
const tangent = n1.clone().add(n2).add(n3).normalize();
|
|
90
|
+
face.tangent = tangent;
|
|
91
|
+
}
|
|
92
|
+
if (uvs)
|
|
93
|
+
{
|
|
94
|
+
const uv_a = new Vector2();
|
|
95
|
+
uv_a.x = uvs.getX(index_0);
|
|
96
|
+
uv_a.y = uvs.getY(index_0);
|
|
97
|
+
|
|
98
|
+
const uv_b = new Vector2();
|
|
99
|
+
uv_b.x = uvs.getX(index_1);
|
|
100
|
+
uv_b.y = uvs.getY(index_1);
|
|
101
|
+
|
|
102
|
+
const uv_c = new Vector2();
|
|
103
|
+
uv_c.x = uvs.getX(index_2);
|
|
104
|
+
uv_c.y = uvs.getY(index_2);
|
|
105
|
+
|
|
106
|
+
face.uv_a = uv_a;
|
|
107
|
+
face.uv_b = uv_b;
|
|
108
|
+
face.uv_c = uv_c;
|
|
109
|
+
}
|
|
110
|
+
|
|
69
111
|
faces.push(face);
|
|
70
112
|
|
|
71
113
|
const area = this.get_face_area(face);
|
|
@@ -83,6 +125,9 @@ class MeshSampler
|
|
|
83
125
|
{
|
|
84
126
|
const sampled_points = [];
|
|
85
127
|
const sampled_normals = [];
|
|
128
|
+
const sampled_tangents = [];
|
|
129
|
+
const sampled_uvs = [];
|
|
130
|
+
|
|
86
131
|
for (let i = 0; i < faces.length; i++)
|
|
87
132
|
{
|
|
88
133
|
const face = faces[i];
|
|
@@ -95,8 +140,16 @@ class MeshSampler
|
|
|
95
140
|
{
|
|
96
141
|
sampled_normals.push(face.normal.clone());
|
|
97
142
|
}
|
|
143
|
+
if (face.tangent)
|
|
144
|
+
{
|
|
145
|
+
sampled_tangents.push(face.tangent.clone());
|
|
146
|
+
}
|
|
147
|
+
if (face.uv_a)
|
|
148
|
+
{
|
|
149
|
+
sampled_uvs.push(this.sample_point_in_face(w1, w2, face.uv_a, face.uv_b, face.uv_c).clone());
|
|
150
|
+
}
|
|
98
151
|
}
|
|
99
|
-
return { points: sampled_points, normals: sampled_normals };
|
|
152
|
+
return { points: sampled_points, normals: sampled_normals, tangents: sampled_tangents, uvs: sampled_uvs };
|
|
100
153
|
}
|
|
101
154
|
|
|
102
155
|
select_random_faces(faces, amount)
|