summaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
Diffstat (limited to 'client')
-rw-r--r--client/splash/face/index.js4
-rw-r--r--client/splash/face/markers.js17
-rw-r--r--client/splash/face/mesh.js110
-rw-r--r--client/splash/index.js1
-rw-r--r--client/util/vendor/geometryHelper.js132
5 files changed, 134 insertions, 130 deletions
diff --git a/client/splash/face/index.js b/client/splash/face/index.js
index 49246e10..157a51cf 100644
--- a/client/splash/face/index.js
+++ b/client/splash/face/index.js
@@ -16,3 +16,7 @@ export function load() {
markers.swap(face)
mesh.load(name)
}
+
+export function update(){
+ markers.update()
+} \ No newline at end of file
diff --git a/client/splash/face/markers.js b/client/splash/face/markers.js
index 6e226228..1832824c 100644
--- a/client/splash/face/markers.js
+++ b/client/splash/face/markers.js
@@ -8,11 +8,12 @@ import { getLineGeometry, updateFace, lerpPoints } from './util'
import { POINT_SCALE, LINE_THICKNESS, FACE_POINT_COUNT, MARKER_COLORS } from '../constants'
-let cubes
-let meshes = []
-
const faceBuffer = Array.from({ length: FACE_POINT_COUNT }, () => new THREE.Vector3())
+let group = new THREE.Object3D()
+let cubes
+let meshes
+
let swapFrom
let swapTo
@@ -36,7 +37,7 @@ export function build(points) {
geometry.applyMatrix(matrix)
let material = new THREE.MeshBasicMaterial({ color: color.setHex(0xffffff) })
let cube = new THREE.Mesh(geometry, material)
- scene.add(cube)
+ group.add(cube)
return cube
})
@@ -49,10 +50,12 @@ export function build(points) {
line.setGeometry(geometry, () => LINE_THICKNESS)
const mesh = new THREE.Mesh(line.geometry, material)
mesh.geometry.dynamic = true
- scene.add(mesh)
+ group.add(mesh)
return [line, mesh]
})
+ scene.add(group)
+
updateFace(points, cubes, meshes)
}
@@ -73,3 +76,7 @@ export function swap(face) {
}
})
}
+
+export function update() {
+ group.rotation.y += 0.005
+} \ No newline at end of file
diff --git a/client/splash/face/mesh.js b/client/splash/face/mesh.js
index de8cd28c..61c4e498 100644
--- a/client/splash/face/mesh.js
+++ b/client/splash/face/mesh.js
@@ -1,4 +1,4 @@
-import { Mesh, MeshBasicMaterial, VertexColors, TrianglesDrawMode } from 'three'
+import { Points, Mesh, MeshBasicMaterial, VertexColors, TrianglesDrawMode } from 'three'
import { scene } from '../renderer'
@@ -28,101 +28,93 @@ export function update(name) {
}
function setDequantizationForMaterial(material, bufferGeometry) {
- material.onBeforeCompile = function(shader) {
+ material.onBeforeCompile = (shader) => {
// Add uniform variables needed for dequantization.
- var posAttribute = bufferGeometry.attributes['position'];
- shader.uniforms.normConstant =
- { value: posAttribute.maxRange / (1 << posAttribute.numQuantizationBits) };
- shader.uniforms.minPos = { value: posAttribute.minValues };
+ const posAttribute = bufferGeometry.attributes.position
+ shader.uniforms.normConstant = { value: posAttribute.maxRange / (1 << posAttribute.numQuantizationBits) }
+ shader.uniforms.minPos = { value: posAttribute.minValues }
shader.vertexShader = 'uniform float maxRange;\n' +
'uniform float normConstant;\n' +
'uniform vec3 minPos;\n' +
- shader.vertexShader;
+ shader.vertexShader
shader.vertexShader = shader.vertexShader.replace(
- '#include <begin_vertex>',
- 'vec3 transformed = minPos + position * normConstant;'
- );
+ '#include <begin_vertex>',
+ 'vec3 transformed = minPos + position * normConstant;'
+ )
}
}
-export function loadFromPath() {
+export function loadFromFile(buf) {
// Enable logging to console output.
dracoLoader.setVerbosity(1)
// To use triangle strips use:
// dracoLoader.setDrawMode(THREE.TriangleStripDrawMode)
- dracoLoader.setDrawMode(THREE.TrianglesDrawMode)
+ dracoLoader.setDrawMode(TrianglesDrawMode)
// Skip dequantization of the position attribute. It will be done on the GPU.
dracoLoader.setSkipDequantization('position', true)
- dracoLoader.decodeDracoFile(reader.result, function(bufferGeometry) {
+ dracoLoader.decodeDracoFile(buf, (bufferGeometry) => {
// if (dracoLoader.decode_time !== undefined) {
// fileDisplayArea.innerText = 'Decode time = ' + dracoLoader.decode_time + '\n' +
// 'Import time = ' + dracoLoader.import_time
// }
- var material = new THREE.MeshBasicMaterial({ vertexColors: VertexColors })
+ const material = new MeshBasicMaterial({ vertexColors: VertexColors })
material.wireframe = true
// If the position attribute is quantized, modify the material to perform
// dequantization on the GPU.
- if (bufferGeometry.attributes['position'].isQuantized) {
+ if (bufferGeometry.attributes.position.isQuantized) {
setDequantizationForMaterial(material, bufferGeometry)
}
- var geometry;
+ let geometry
// Point cloud does not have face indices.
- if (bufferGeometry.index == null) {
- geometry = new THREE.Points(bufferGeometry, material);
+ if (bufferGeometry.index === null) {
+ geometry = new Points(bufferGeometry, material)
} else {
if (bufferGeometry.attributes.normal === undefined) {
- var geometryHelper = new GeometryHelper();
- geometryHelper.computeVertexNormals(bufferGeometry);
+ const geometryHelper = new GeometryHelper()
+ geometryHelper.computeVertexNormals(bufferGeometry)
}
- geometry = new THREE.Mesh(bufferGeometry, material);
- geometry.drawMode = dracoLoader.drawMode;
+ geometry = new Mesh(bufferGeometry, material)
+ geometry.drawMode = dracoLoader.drawMode
}
// Compute range of the geometry coordinates for proper rendering.
- bufferGeometry.computeBoundingBox();
- if (bufferGeometry.attributes['position'].isQuantized) {
+ bufferGeometry.computeBoundingBox()
+ if (bufferGeometry.attributes.position.isQuantized) {
// If the geometry is quantized, transform the bounding box to the dequantized
// coordinates.
- var posAttribute = bufferGeometry.attributes['position'];
- var normConstant =
- posAttribute.maxRange / (1 << posAttribute.numQuantizationBits);
- var minPos = posAttribute.minValues;
- bufferGeometry.boundingBox.max.x =
- minPos[0] + bufferGeometry.boundingBox.max.x * normConstant;
- bufferGeometry.boundingBox.max.y =
- minPos[1] + bufferGeometry.boundingBox.max.y * normConstant;
- bufferGeometry.boundingBox.max.z =
- minPos[2] + bufferGeometry.boundingBox.max.z * normConstant;
- bufferGeometry.boundingBox.min.x =
- minPos[0] + bufferGeometry.boundingBox.min.x * normConstant;
- bufferGeometry.boundingBox.min.y =
- minPos[1] + bufferGeometry.boundingBox.min.y * normConstant;
- bufferGeometry.boundingBox.min.z =
- minPos[2] + bufferGeometry.boundingBox.min.z * normConstant;
+ const posAttribute = bufferGeometry.attributes.position
+ const normConstant = posAttribute.maxRange / (1 << posAttribute.numQuantizationBits)
+ const minPos = posAttribute.minValues
+ bufferGeometry.boundingBox.max.x = minPos[0] + bufferGeometry.boundingBox.max.x * normConstant
+ bufferGeometry.boundingBox.max.y = minPos[1] + bufferGeometry.boundingBox.max.y * normConstant
+ bufferGeometry.boundingBox.max.z = minPos[2] + bufferGeometry.boundingBox.max.z * normConstant
+ bufferGeometry.boundingBox.min.x = minPos[0] + bufferGeometry.boundingBox.min.x * normConstant
+ bufferGeometry.boundingBox.min.y = minPos[1] + bufferGeometry.boundingBox.min.y * normConstant
+ bufferGeometry.boundingBox.min.z = minPos[2] + bufferGeometry.boundingBox.min.z * normConstant
}
- var sizeX = bufferGeometry.boundingBox.max.x - bufferGeometry.boundingBox.min.x;
- var sizeY = bufferGeometry.boundingBox.max.y - bufferGeometry.boundingBox.min.y;
- var sizeZ = bufferGeometry.boundingBox.max.z - bufferGeometry.boundingBox.min.z;
- var diagonalSize = Math.sqrt(sizeX * sizeX + sizeY * sizeY + sizeZ * sizeZ);
- var scale = 1.0 / diagonalSize;
- var midX = (bufferGeometry.boundingBox.min.x + bufferGeometry.boundingBox.max.x) / 2;
- var midY = (bufferGeometry.boundingBox.min.y + bufferGeometry.boundingBox.max.y) / 2;
- var midZ = (bufferGeometry.boundingBox.min.z + bufferGeometry.boundingBox.max.z) / 2;
+ const sizeX = bufferGeometry.boundingBox.max.x - bufferGeometry.boundingBox.min.x
+ const sizeY = bufferGeometry.boundingBox.max.y - bufferGeometry.boundingBox.min.y
+ const sizeZ = bufferGeometry.boundingBox.max.z - bufferGeometry.boundingBox.min.z
+ const diagonalSize = Math.sqrt(sizeX * sizeX + sizeY * sizeY + sizeZ * sizeZ)
+ const scale = 1.0 / diagonalSize
+ const midX = (bufferGeometry.boundingBox.min.x + bufferGeometry.boundingBox.max.x) / 2
+ const midY = (bufferGeometry.boundingBox.min.y + bufferGeometry.boundingBox.max.y) / 2
+ const midZ = (bufferGeometry.boundingBox.min.z + bufferGeometry.boundingBox.max.z) / 2
- geometry.scale.multiplyScalar(scale);
- geometry.position.x = -midX * scale;
- geometry.position.y = -midY * scale;
- geometry.position.z = -midZ * scale;
- // geometry.castShadow = true;
- // geometry.receiveShadow = true;
+ geometry.scale.multiplyScalar(scale)
+ geometry.position.x = -midX * scale
+ geometry.position.y = -midY * scale
+ geometry.position.z = -midZ * scale
+ // geometry.castShadow = true
+ // geometry.receiveShadow = true
- var selectedObject = scene.getObjectByName("my_mesh");
- scene.remove(selectedObject);
- geometry.name = "my_mesh";
- scene.add(geometry);
- });
+ const selectedObject = scene.getObjectByName("my_mesh")
+ scene.remove(selectedObject)
+ geometry.name = "my_mesh"
+ scene.add(geometry)
+ })
}
diff --git a/client/splash/index.js b/client/splash/index.js
index 76c84ec0..24561b80 100644
--- a/client/splash/index.js
+++ b/client/splash/index.js
@@ -24,6 +24,7 @@ function animate() {
controls.update()
cloud.update()
+ face.update()
let cameraTarget = new Vector3(0, 0, 0)
camera.lookAt(cameraTarget)
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