@shapediver/viewer.shared.math
Advanced tools
Comparing version 2.9.12 to 2.9.13
@@ -112,15 +112,30 @@ "use strict"; | ||
} | ||
setFromAttributeArray(array, stride, bytes, matrix = gl_matrix_1.mat4.create()) { | ||
let transformedArray = []; | ||
setFromAttributeArray(array, stride, bytes, matrix) { | ||
const length = (Math.floor(array.length / 3) * 3); | ||
const byteStride = (stride && stride !== bytes) ? +stride : 3; | ||
const min = [Infinity, Infinity, Infinity]; | ||
const max = [-Infinity, -Infinity, -Infinity]; | ||
let x, y, z; | ||
const point = gl_matrix_1.vec4.create(); | ||
for (let i = 0; i < length; i += byteStride) { | ||
let point = gl_matrix_1.vec4.transformMat4(gl_matrix_1.vec4.create(), gl_matrix_1.vec4.fromValues(array[i], array[i + 1], array[i + 2], 1), matrix); | ||
transformedArray.push([point[0] / point[3], point[1] / point[3], point[2] / point[3]]); | ||
if (matrix) { | ||
gl_matrix_1.vec4.transformMat4(point, [array[i], array[i + 1], array[i + 2], 1], matrix); | ||
x = point[0] / point[3]; | ||
y = point[1] / point[3]; | ||
z = point[2] / point[3]; | ||
} | ||
else { | ||
x = array[i]; | ||
y = array[i + 1]; | ||
z = array[i + 2]; | ||
} | ||
min[0] = Math.min(min[0], x); | ||
min[1] = Math.min(min[1], y); | ||
min[2] = Math.min(min[2], z); | ||
max[0] = Math.max(max[0], x); | ||
max[1] = Math.max(max[1], y); | ||
max[2] = Math.max(max[2], z); | ||
} | ||
let x_coords = transformedArray.map(p => p[0]); | ||
let y_coords = transformedArray.map(p => p[1]); | ||
let z_coords = transformedArray.map(p => p[2]); | ||
this.min = gl_matrix_1.vec3.fromValues(Math.min(...x_coords), Math.min(...y_coords), Math.min(...z_coords)); | ||
this.max = gl_matrix_1.vec3.fromValues(Math.max(...x_coords), Math.max(...y_coords), Math.max(...z_coords)); | ||
this.min = gl_matrix_1.vec3.fromValues(min[0], min[1], min[2]); | ||
this.max = gl_matrix_1.vec3.fromValues(max[0], max[1], max[2]); | ||
return this; | ||
@@ -127,0 +142,0 @@ } |
{ | ||
"name": "@shapediver/viewer.shared.math", | ||
"version": "2.9.12", | ||
"version": "2.9.13", | ||
"description": "", | ||
@@ -42,6 +42,6 @@ "keywords": [], | ||
"dependencies": { | ||
"@shapediver/viewer.shared.services": "2.9.12", | ||
"@shapediver/viewer.shared.services": "2.9.13", | ||
"gl-matrix": "3.3.0" | ||
}, | ||
"gitHead": "64a3583144cce3bc3191b809285966b6cd807a95" | ||
"gitHead": "d05a7c78b4560c63ed4f4dd6970e3cc6b2c90aa7" | ||
} |
@@ -136,17 +136,34 @@ import { mat4, vec3, vec4 } from 'gl-matrix' | ||
public setFromAttributeArray(array: Int8Array | Uint8Array | Int16Array | Uint16Array | Uint32Array | Float32Array, stride?: number, bytes?: number, matrix: mat4 = mat4.create()): IBox { | ||
let transformedArray = []; | ||
public setFromAttributeArray(array: Int8Array | Uint8Array | Int16Array | Uint16Array | Uint32Array | Float32Array, stride?: number, bytes?: number, matrix?: mat4): IBox { | ||
const length = (Math.floor(array.length / 3) * 3); | ||
const byteStride = (stride && stride !== bytes) ? +stride : 3; | ||
const min = [Infinity, Infinity, Infinity]; | ||
const max = [-Infinity, -Infinity, -Infinity]; | ||
let x, y, z; | ||
const point = vec4.create(); | ||
for (let i = 0; i < length; i += byteStride) { | ||
let point = vec4.transformMat4(vec4.create(), vec4.fromValues(array[i], array[i + 1], array[i + 2], 1), matrix); | ||
transformedArray.push([point[0] / point[3], point[1] / point[3], point[2] / point[3]]); | ||
if(matrix) { | ||
vec4.transformMat4(point, [array[i], array[i + 1], array[i + 2], 1], matrix); | ||
x = point[0] / point[3]; | ||
y = point[1] / point[3]; | ||
z = point[2] / point[3]; | ||
} else { | ||
x = array[i]; | ||
y = array[i + 1]; | ||
z = array[i + 2]; | ||
} | ||
min[0] = Math.min(min[0], x); | ||
min[1] = Math.min(min[1], y); | ||
min[2] = Math.min(min[2], z); | ||
max[0] = Math.max(max[0], x); | ||
max[1] = Math.max(max[1], y); | ||
max[2] = Math.max(max[2], z); | ||
} | ||
let x_coords = transformedArray.map(p => p[0]); | ||
let y_coords = transformedArray.map(p => p[1]); | ||
let z_coords = transformedArray.map(p => p[2]); | ||
this.min = vec3.fromValues(Math.min(...x_coords), Math.min(...y_coords), Math.min(...z_coords)); | ||
this.max = vec3.fromValues(Math.max(...x_coords), Math.max(...y_coords), Math.max(...z_coords)); | ||
this.min = vec3.fromValues(min[0], min[1], min[2]); | ||
this.max = vec3.fromValues(max[0], max[1], max[2]); | ||
@@ -153,0 +170,0 @@ return this; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86878
1112
+ Added@shapediver/viewer.shared.build-data@2.9.13(transitive)
+ Added@shapediver/viewer.shared.services@2.9.13(transitive)
- Removed@shapediver/viewer.shared.build-data@2.9.12(transitive)
- Removed@shapediver/viewer.shared.services@2.9.12(transitive)