diff options
Diffstat (limited to 'client/splash')
| -rw-r--r-- | client/splash/face/index.js | 4 | ||||
| -rw-r--r-- | client/splash/face/markers.js | 17 | ||||
| -rw-r--r-- | client/splash/face/mesh.js | 110 | ||||
| -rw-r--r-- | client/splash/index.js | 1 |
4 files changed, 68 insertions, 64 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) |
