summaryrefslogtreecommitdiff
path: root/client/util/vendor
diff options
context:
space:
mode:
Diffstat (limited to 'client/util/vendor')
-rw-r--r--client/util/vendor/geometryHelper.js132
1 files changed, 66 insertions, 66 deletions
diff --git a/client/util/vendor/geometryHelper.js b/client/util/vendor/geometryHelper.js
index 1ac88f3b..7f699722 100644
--- a/client/util/vendor/geometryHelper.js
+++ b/client/util/vendor/geometryHelper.js
@@ -23,84 +23,84 @@ import * as THREE from 'three';
function GeometryHelper() {}
GeometryHelper.prototype = {
- constructor: GeometryHelper,
+ constructor: GeometryHelper,
- // Computes vertex normals on THREE.js buffer geometry, even when the mesh
- // uses triangle strip connectivity.
- computeVertexNormals: function (bufferGeometry) {
- if (bufferGeometry.drawMode === THREE.TrianglesDrawMode) {
- bufferGeometry.computeVertexNormals();
+ // Computes vertex normals on THREE.js buffer geometry, even when the mesh
+ // uses triangle strip connectivity.
+ computeVertexNormals: function (bufferGeometry) {
+ if (bufferGeometry.drawMode === THREE.TrianglesDrawMode) {
+ bufferGeometry.computeVertexNormals();
+ return;
+ } else if (bufferGeometry.drawMode === THREE.TriangleStripDrawMode) {
+ if (bufferGeometry.attributes.position === undefined) {
return;
- } else if (bufferGeometry.drawMode === THREE.TriangleStripDrawMode) {
- if (bufferGeometry.attributes.position === undefined) {
- return;
- }
- const inPositions = bufferGeometry.attributes.position.array;
- if (bufferGeometry.attributes.normal === undefined) {
- bufferGeometry.addAttribute(
- 'normal',
- new THREE.BufferAttribute(new Float32Array(inPositions.length),
- 3));
- } else {
- // Reset existing normals to zero.
- const array = bufferGeometry.attributes.normal.array;
- for (let i = 0; i < array.length; ++i) {
- array[ i ] = 0;
- }
+ }
+ const inPositions = bufferGeometry.attributes.position.array;
+ if (bufferGeometry.attributes.normal === undefined) {
+ bufferGeometry.addAttribute(
+ 'normal',
+ new THREE.BufferAttribute(new Float32Array(inPositions.length),
+ 3));
+ } else {
+ // Reset existing normals to zero.
+ const array = bufferGeometry.attributes.normal.array;
+ for (let i = 0; i < array.length; ++i) {
+ array[ i ] = 0;
}
- let outNormals = bufferGeometry.attributes.normal.array;
+ }
+ let outNormals = bufferGeometry.attributes.normal.array;
- let pos0 = new THREE.Vector3();
- let pos1 = new THREE.Vector3();
- let pos2 = new THREE.Vector3();
- let posDif0 = new THREE.Vector3(), posDif1 = new THREE.Vector3();
- let localNormal = new THREE.Vector3();
+ let pos0 = new THREE.Vector3();
+ let pos1 = new THREE.Vector3();
+ let pos2 = new THREE.Vector3();
+ let posDif0 = new THREE.Vector3(), posDif1 = new THREE.Vector3();
+ let localNormal = new THREE.Vector3();
- const stripIndices = bufferGeometry.index.array;
- for (let i = 2; i < stripIndices.length; ++i) {
- let index0 = stripIndices[i - 2] * 3;
- let index1 = stripIndices[i - 1] * 3;
- let index2 = stripIndices[i] * 3;
- // Skip degenerate triangles.
- if (index0 === index1 || index0 === index2 || index1 === index2) {
- continue;
- }
- if ((i & 1) !== 0) {
- // Swap index 1 and 0 on odd indexed triangles.
- const tmpIndex = index1;
- index1 = index2;
- index2 = tmpIndex;
- }
+ const stripIndices = bufferGeometry.index.array;
+ for (let i = 2; i < stripIndices.length; ++i) {
+ let index0 = stripIndices[i - 2] * 3;
+ let index1 = stripIndices[i - 1] * 3;
+ let index2 = stripIndices[i] * 3;
+ // Skip degenerate triangles.
+ if (index0 === index1 || index0 === index2 || index1 === index2) {
+ continue;
+ }
+ if ((i & 1) !== 0) {
+ // Swap index 1 and 0 on odd indexed triangles.
+ const tmpIndex = index1;
+ index1 = index2;
+ index2 = tmpIndex;
+ }
- // Get position values.
- pos0.fromArray(inPositions, index0);
- pos1.fromArray(inPositions, index1);
- pos2.fromArray(inPositions, index2);
+ // Get position values.
+ pos0.fromArray(inPositions, index0);
+ pos1.fromArray(inPositions, index1);
+ pos2.fromArray(inPositions, index2);
- // Position differences
- posDif0.subVectors(pos2, pos0);
- posDif1.subVectors(pos1, pos0);
+ // Position differences
+ posDif0.subVectors(pos2, pos0);
+ posDif1.subVectors(pos1, pos0);
- // Weighted normal.
- localNormal.crossVectors(posDif1, posDif0);
+ // Weighted normal.
+ localNormal.crossVectors(posDif1, posDif0);
- // Update normals on vertices
- outNormals[index0] += localNormal.x;
- outNormals[index0 + 1] += localNormal.y;
- outNormals[index0 + 2] += localNormal.z;
+ // Update normals on vertices
+ outNormals[index0] += localNormal.x;
+ outNormals[index0 + 1] += localNormal.y;
+ outNormals[index0 + 2] += localNormal.z;
- outNormals[index1] += localNormal.x;
- outNormals[index1 + 1] += localNormal.y;
- outNormals[index1 + 2] += localNormal.z;
+ outNormals[index1] += localNormal.x;
+ outNormals[index1 + 1] += localNormal.y;
+ outNormals[index1 + 2] += localNormal.z;
- outNormals[index2] += localNormal.x;
- outNormals[index2 + 1] += localNormal.y;
- outNormals[index2 + 2] += localNormal.z;
- }
- bufferGeometry.normalizeNormals();
- bufferGeometry.attributes.normal.needsUpdate = true;
+ outNormals[index2] += localNormal.x;
+ outNormals[index2 + 1] += localNormal.y;
+ outNormals[index2 + 2] += localNormal.z;
}
- },
+ bufferGeometry.normalizeNormals();
+ bufferGeometry.attributes.normal.needsUpdate = true;
+ }
+ },
};
export default GeometryHelper