|
@@ -14,6 +14,7 @@
|
|
export class VertexData {
|
|
export class VertexData {
|
|
public positions: number[] | Float32Array;
|
|
public positions: number[] | Float32Array;
|
|
public normals: number[] | Float32Array;
|
|
public normals: number[] | Float32Array;
|
|
|
|
+ public tangents: number[] | Float32Array;
|
|
public uvs: number[] | Float32Array;
|
|
public uvs: number[] | Float32Array;
|
|
public uvs2: number[] | Float32Array;
|
|
public uvs2: number[] | Float32Array;
|
|
public uvs3: number[] | Float32Array;
|
|
public uvs3: number[] | Float32Array;
|
|
@@ -35,6 +36,9 @@
|
|
case VertexBuffer.NormalKind:
|
|
case VertexBuffer.NormalKind:
|
|
this.normals = data;
|
|
this.normals = data;
|
|
break;
|
|
break;
|
|
|
|
+ case VertexBuffer.TangentKind:
|
|
|
|
+ this.tangents = data;
|
|
|
|
+ break;
|
|
case VertexBuffer.UVKind:
|
|
case VertexBuffer.UVKind:
|
|
this.uvs = data;
|
|
this.uvs = data;
|
|
break;
|
|
break;
|
|
@@ -118,6 +122,10 @@
|
|
meshOrGeometry.setVerticesData(VertexBuffer.NormalKind, this.normals, updatable);
|
|
meshOrGeometry.setVerticesData(VertexBuffer.NormalKind, this.normals, updatable);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (this.tangents) {
|
|
|
|
+ meshOrGeometry.setVerticesData(VertexBuffer.TangentKind, this.tangents, updatable);
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this.uvs) {
|
|
if (this.uvs) {
|
|
meshOrGeometry.setVerticesData(VertexBuffer.UVKind, this.uvs, updatable);
|
|
meshOrGeometry.setVerticesData(VertexBuffer.UVKind, this.uvs, updatable);
|
|
}
|
|
}
|
|
@@ -177,6 +185,10 @@
|
|
meshOrGeometry.updateVerticesData(VertexBuffer.NormalKind, this.normals, updateExtends, makeItUnique);
|
|
meshOrGeometry.updateVerticesData(VertexBuffer.NormalKind, this.normals, updateExtends, makeItUnique);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (this.tangents) {
|
|
|
|
+ meshOrGeometry.updateVerticesData(VertexBuffer.TangentKind, this.tangents, updateExtends, makeItUnique);
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this.uvs) {
|
|
if (this.uvs) {
|
|
meshOrGeometry.updateVerticesData(VertexBuffer.UVKind, this.uvs, updateExtends, makeItUnique);
|
|
meshOrGeometry.updateVerticesData(VertexBuffer.UVKind, this.uvs, updateExtends, makeItUnique);
|
|
}
|
|
}
|
|
@@ -259,6 +271,22 @@
|
|
this.normals[index + 2] = transformed.z;
|
|
this.normals[index + 2] = transformed.z;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (this.tangents) {
|
|
|
|
+ var tangent = Vector4.Zero();
|
|
|
|
+ var tangentTransformed = Vector4.Zero();
|
|
|
|
+
|
|
|
|
+ for (index = 0; index < this.tangents.length; index += 4) {
|
|
|
|
+ Vector4.FromArrayToRef(this.tangents, index, tangent);
|
|
|
|
+
|
|
|
|
+ Vector4.TransformNormalToRef(tangent, matrix, tangentTransformed);
|
|
|
|
+ this.tangents[index] = tangentTransformed.x;
|
|
|
|
+ this.tangents[index + 1] = tangentTransformed.y;
|
|
|
|
+ this.tangents[index + 2] = tangentTransformed.z;
|
|
|
|
+ this.tangents[index + 3] = tangentTransformed.w;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
return this;
|
|
return this;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -281,6 +309,7 @@
|
|
|
|
|
|
this.positions = this._mergeElement(this.positions, other.positions);
|
|
this.positions = this._mergeElement(this.positions, other.positions);
|
|
this.normals = this._mergeElement(this.normals, other.normals);
|
|
this.normals = this._mergeElement(this.normals, other.normals);
|
|
|
|
+ this.tangents = this._mergeElement(this.tangents, other.tangents);
|
|
this.uvs = this._mergeElement(this.uvs, other.uvs);
|
|
this.uvs = this._mergeElement(this.uvs, other.uvs);
|
|
this.uvs2 = this._mergeElement(this.uvs2, other.uvs2);
|
|
this.uvs2 = this._mergeElement(this.uvs2, other.uvs2);
|
|
this.uvs3 = this._mergeElement(this.uvs3, other.uvs3);
|
|
this.uvs3 = this._mergeElement(this.uvs3, other.uvs3);
|
|
@@ -339,6 +368,10 @@
|
|
serializationObject.normals = this.normals;
|
|
serializationObject.normals = this.normals;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (this.tangents) {
|
|
|
|
+ serializationObject.tangents = this.tangents;
|
|
|
|
+ }
|
|
|
|
+
|
|
if (this.uvs) {
|
|
if (this.uvs) {
|
|
serializationObject.uvs = this.uvs;
|
|
serializationObject.uvs = this.uvs;
|
|
}
|
|
}
|
|
@@ -416,6 +449,10 @@
|
|
result.normals = meshOrGeometry.getVerticesData(VertexBuffer.NormalKind, copyWhenShared);
|
|
result.normals = meshOrGeometry.getVerticesData(VertexBuffer.NormalKind, copyWhenShared);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.TangentKind)) {
|
|
|
|
+ result.tangents = meshOrGeometry.getVerticesData(VertexBuffer.TangentKind, copyWhenShared);
|
|
|
|
+ }
|
|
|
|
+
|
|
if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UVKind)) {
|
|
if (meshOrGeometry.isVerticesDataPresent(VertexBuffer.UVKind)) {
|
|
result.uvs = meshOrGeometry.getVerticesData(VertexBuffer.UVKind, copyWhenShared);
|
|
result.uvs = meshOrGeometry.getVerticesData(VertexBuffer.UVKind, copyWhenShared);
|
|
}
|
|
}
|
|
@@ -2061,7 +2098,7 @@
|
|
* bbSize : optional bounding box size data, required for facetPartitioning computation
|
|
* bbSize : optional bounding box size data, required for facetPartitioning computation
|
|
* bInfo : optional bounding info, required for facetPartitioning computation
|
|
* bInfo : optional bounding info, required for facetPartitioning computation
|
|
*/
|
|
*/
|
|
- public static ComputeNormals(positions: any, indices: any, normals: any,
|
|
|
|
|
|
+ public static ComputeNormals(positions: any, indices: any, normals: any,
|
|
options?: { facetNormals?: any, facetPositions?: any, facetPartitioning?: any, ratio?: number, bInfo?: any, bbSize?: Vector3, subDiv?: any}): void {
|
|
options?: { facetNormals?: any, facetPositions?: any, facetPartitioning?: any, ratio?: number, bInfo?: any, bbSize?: Vector3, subDiv?: any}): void {
|
|
|
|
|
|
// temporary scalar variables
|
|
// temporary scalar variables
|
|
@@ -2095,7 +2132,7 @@
|
|
}
|
|
}
|
|
|
|
|
|
// facetPartitioning reinit if needed
|
|
// facetPartitioning reinit if needed
|
|
- if (computeFacetPartitioning) {
|
|
|
|
|
|
+ if (computeFacetPartitioning) {
|
|
var ox = 0; // X partitioning index for facet position
|
|
var ox = 0; // X partitioning index for facet position
|
|
var oy = 0; // Y partinioning index for facet position
|
|
var oy = 0; // Y partinioning index for facet position
|
|
var oz = 0; // Z partinioning index for facet position
|
|
var oz = 0; // Z partinioning index for facet position
|
|
@@ -2121,7 +2158,7 @@
|
|
var subSq = options.subDiv.max * options.subDiv.max;
|
|
var subSq = options.subDiv.max * options.subDiv.max;
|
|
options.facetPartitioning.length = 0;
|
|
options.facetPartitioning.length = 0;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
// reset the normals
|
|
// reset the normals
|
|
for (index = 0; index < positions.length; index++) {
|
|
for (index = 0; index < positions.length; index++) {
|
|
normals[index] = 0.0;
|
|
normals[index] = 0.0;
|
|
@@ -2140,7 +2177,7 @@
|
|
v2z = v2x + 2;
|
|
v2z = v2x + 2;
|
|
v3x = indices[index * 3 + 2] * 3;
|
|
v3x = indices[index * 3 + 2] * 3;
|
|
v3y = v3x + 1;
|
|
v3y = v3x + 1;
|
|
- v3z = v3x + 2;
|
|
|
|
|
|
+ v3z = v3x + 2;
|
|
|
|
|
|
p1p2x = positions[v1x] - positions[v2x]; // compute two vectors per facet : p1p2 and p3p2
|
|
p1p2x = positions[v1x] - positions[v2x]; // compute two vectors per facet : p1p2 and p3p2
|
|
p1p2y = positions[v1y] - positions[v2y];
|
|
p1p2y = positions[v1y] - positions[v2y];
|
|
@@ -2151,7 +2188,7 @@
|
|
p3p2z = positions[v3z] - positions[v2z];
|
|
p3p2z = positions[v3z] - positions[v2z];
|
|
|
|
|
|
// compute the face normal with the cross product
|
|
// compute the face normal with the cross product
|
|
- faceNormalx = p1p2y * p3p2z - p1p2z * p3p2y;
|
|
|
|
|
|
+ faceNormalx = p1p2y * p3p2z - p1p2z * p3p2y;
|
|
faceNormaly = p1p2z * p3p2x - p1p2x * p3p2z;
|
|
faceNormaly = p1p2z * p3p2x - p1p2x * p3p2z;
|
|
faceNormalz = p1p2x * p3p2y - p1p2y * p3p2x;
|
|
faceNormalz = p1p2x * p3p2y - p1p2y * p3p2x;
|
|
// normalize this normal and store it in the array facetData
|
|
// normalize this normal and store it in the array facetData
|
|
@@ -2162,7 +2199,7 @@
|
|
faceNormalz /= length;
|
|
faceNormalz /= length;
|
|
|
|
|
|
if (computeFacetNormals) {
|
|
if (computeFacetNormals) {
|
|
- options.facetNormals[index].x = faceNormalx;
|
|
|
|
|
|
+ options.facetNormals[index].x = faceNormalx;
|
|
options.facetNormals[index].y = faceNormaly;
|
|
options.facetNormals[index].y = faceNormaly;
|
|
options.facetNormals[index].z = faceNormalz;
|
|
options.facetNormals[index].z = faceNormalz;
|
|
}
|
|
}
|
|
@@ -2189,7 +2226,7 @@
|
|
b3x = Math.floor((positions[v3x] - options.bInfo.minimum.x * options.ratio) * xSubRatio);
|
|
b3x = Math.floor((positions[v3x] - options.bInfo.minimum.x * options.ratio) * xSubRatio);
|
|
b3y = Math.floor((positions[v3y] - options.bInfo.minimum.y * options.ratio) * ySubRatio);
|
|
b3y = Math.floor((positions[v3y] - options.bInfo.minimum.y * options.ratio) * ySubRatio);
|
|
b3z = Math.floor((positions[v3z] - options.bInfo.minimum.z * options.ratio) * zSubRatio);
|
|
b3z = Math.floor((positions[v3z] - options.bInfo.minimum.z * options.ratio) * zSubRatio);
|
|
-
|
|
|
|
|
|
+
|
|
block_idx_v1 = b1x + options.subDiv.max * b1y + subSq * b1z;
|
|
block_idx_v1 = b1x + options.subDiv.max * b1y + subSq * b1z;
|
|
block_idx_v2 = b2x + options.subDiv.max * b2y + subSq * b2z;
|
|
block_idx_v2 = b2x + options.subDiv.max * b2y + subSq * b2z;
|
|
block_idx_v3 = b3x + options.subDiv.max * b3y + subSq * b3z;
|
|
block_idx_v3 = b3x + options.subDiv.max * b3y + subSq * b3z;
|
|
@@ -2209,7 +2246,7 @@
|
|
options.facetPartitioning[block_idx_v3].push(index);
|
|
options.facetPartitioning[block_idx_v3].push(index);
|
|
}
|
|
}
|
|
if (!(block_idx_o == block_idx_v1 || block_idx_o == block_idx_v2 || block_idx_o == block_idx_v3)) {
|
|
if (!(block_idx_o == block_idx_v1 || block_idx_o == block_idx_v2 || block_idx_o == block_idx_v3)) {
|
|
- options.facetPartitioning[block_idx_o].push(index);
|
|
|
|
|
|
+ options.facetPartitioning[block_idx_o].push(index);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -2314,6 +2351,12 @@
|
|
vertexData.set(normals, VertexBuffer.NormalKind);
|
|
vertexData.set(normals, VertexBuffer.NormalKind);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // tangents
|
|
|
|
+ var tangents = parsedVertexData.tangents;
|
|
|
|
+ if (tangents) {
|
|
|
|
+ vertexData.set(tangents, VertexBuffer.TangentKind);
|
|
|
|
+ }
|
|
|
|
+
|
|
// uvs
|
|
// uvs
|
|
var uvs = parsedVertexData.uvs;
|
|
var uvs = parsedVertexData.uvs;
|
|
if (uvs) {
|
|
if (uvs) {
|